之前说到Webservice实际就是以http协议交互数据,提交符合约定的XML。那么在之前工具基础上生成调用方法的XML模板,在M里面用%Net.HttpRequest去Post数据调用Webservice一样可行。这种方式比Cache代理类灵活,然后更加有目的,Cache代理类经常莫名奇妙不通还看不出原因。
首先扩展工具顺带生成调用XML模板,用SOAPUI也是一样的
生成的调用模板数据
往URL里指定SOAPAction提交Xml格式数据即可调用
URL:https://119.255.194.169:1443/imedicallis/service/asmx/wbsDHCLISReportServiceHandler.asmx
SOAPAction:http://tempuri.org/Print
XML:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Body><Print xmlns="http://tempuri.org/"><regNo>{0}</regNo><cardType>{1}</cardType><patSelectModel>{2}</patSelectModel></Print></soap:Body></soap:Envelope>
M实现Post方法
/// 往指定URL里Post数据,用于Post和动态请求Webservice
/// w ##Class(LIS.WS.DHCLISServiceBase).PostData("1","119.255.194.169","1443","/imedicallis/service/asmx/wbsDHCLISReportServiceHandler.asmx","http://tempuri.org/Print","<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/08/addressing"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""><soap:Body><Print xmlns=""http://tempuri.org/""><regNo>123456</regNo><cardType></cardType><patSelectModel></patSelectModel></Print></soap:Body></soap:Envelope>")
ClassMethod PostData(Https, Server, Port, Url, SOAPAction, Xml)
{
Set httprequest=##class(%Net.HttpRequest).%New()
Set httprequest.Server=Server
Set httprequest.Port=Port
//https
i Https="1" d
.s httprequest.Https=Https
.//请到 系统 > 安全管理 > SSL/TLS 配置 > 编辑 SSL/TLS 配置配置名称为lis的配置,协议勾选所有,其他默认
.s httprequest.SSLConfiguration="lis"
.s httprequest.SSLCheckServerIdentity=0
Set sc=httprequest.SetHeader("SOAPAction",SOAPAction)
Do httprequest.EntityBody.Write(Xml)
set status=httprequest.Post(Url)
//异常处理
i $$$ISERR(status) d
.d $SYSTEM.Status.DisplayError(status)
.THROW ##class(%Exception.SystemException).%New("调用异常","D",,"往URL里Post数据异常")
s retStr=httprequest.HttpResponse.Data.Read()
q retStr
}
调试调用是没问题的
DHC-LISDATA>w ##Class(LIS.WS.DHCLISServiceBase).PostData("1","119.255.194.169","1443","/imedicallis/service/asmx/wbsDHCLISReportServiceHandler.asmx","http://tempuri.org/Print","<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/08/addressing"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""><soap:Body><Print xmlns=""http://tempuri.org/""><regNo>123456</regNo><cardType></cardType><patSelectModel></patSelectModel></Print></soap:Body></soap:Envelope>")
??<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<PrintResponse xmlns="http://tempuri.org/">
<PrintResult><?xml version="1.0"?>
<RetDto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CanPrint>0</CanPrint>
<NotAuth>0</NotAuth>
<CName />
<DetailList />
</RetDto></PrintResult>
</PrintResponse>
</s:Body>
</s:Envelope>
DHC-LISDATA>