动态调Webservice之M篇

9 篇文章 1 订阅
4 篇文章 0 订阅

之前说到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>&lt;?xml version="1.0"?&gt;
                            &lt;RetDto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
                                                               &lt;CanPrint&gt;0&lt;/CanPrint&gt;
                   &lt;NotAuth&gt;0&lt;/NotAuth&gt;
                                                     &lt;CName /&gt;
                                                                  
                              &lt;DetailList /&gt;
                                                  &lt;/RetDto&gt;</PrintResult>
                                                                                   </PrintResponse>
                     </s:Body>
                              </s:Envelope>
DHC-LISDATA>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小乌鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值