PowerBuilder9.0 使用xmlhttp组件调用webservice

版权声明:本文为博主原创文章,未经博主允许不可以转载。 https://blog.csdn.net/aasmfox/article/details/90030292

病案管理DRGS接口的工作笔记
//-----------------------------------------------------------------------------------------------

今天在这里写个备忘录,以后用到可以当作参考

powerbuilder9.0自带的pbsoapclient.pbd,可以很方便的调用webservices,但是在目标电脑上经常发生运行时错误,
估计是多个pb版本造成的动态库版本不一致引起的。

于是改成使用xmlhttp组件来调用。

1.根据wsdl文件生成报文

2.根据报文例子,生成请求的body,代码如下 

//创建XMLHTTP控件--------------------------------------------------------------------------
http = Create OLEObject 
li_ret = http.ConnectToNewObject( "Msxml2.XMLHTTP")
If li_ret <> 0 Then
	li_ret  = http.ConnectToNewObject( "Msxml2.XMLHTTP.3.0")
End If
if(li_ret <> 0 )  then
	is_error = "Msxml2组件初始化失败!"
	return -1
end if 

//构造报文内容-----------------------------------------------------------------------------
ls_xml = "<?xml version=~"1.0~" encoding=~"utf-8~"?>" 
ls_xml += "<soap:Envelope xmlns:xsi=~"http://www.w3.org/2001/XMLSchema-instance~" xmlns:xsd=~"http://www.w3.org/2001/XMLSchema~" xmlns:soap=~"http://schemas.xmlsoap.org/soap/envelope/~">"
ls_xml += "<soap:Body>"
ls_xml += "<MedicalServiceXml xmlns=~"http://tempuri.org/~">"
ls_xml += "<serviceId>"+is_serviceid+"</serviceId>"
ls_xml += "<userId>"+UserID+"</userId>"
ls_xml += "<nonce>"+nonce+"</nonce>"
ls_xml += "<data>"+is_data+"</data>"
ls_xml += "<siginMethod>"+siginmethod+"</siginMethod>"
ls_xml += "<signData>"+signdata+"</signData>"
ls_xml += "</MedicalServiceXml>"
ls_xml += "</soap:Body>"
ls_xml += "</soap:Envelope>"
 
//转换编码格式UTF8-------------------------------------------------------------------------
CString Conver
Conver.ToUnicode(ls_xml,lblb_args)
ll_length = Len(lblb_args)

//提交请求---------------------------------------------------------------------------------
http.Open("POST",ls_url,True)
http.setRequestHeader("Content-Type","text/xml; charset=utf-8")
http.setRequestHeader("SOAPAction","http://tempuri.org/MedicalServiceXml")
http.setRequestHeader("Content-Length",String(ll_length)) 
http.setRequestHeader("Host","10.84.195.21")
http.Send(lblb_args)

//接收返回结果----------------------------------------------------------------------------- 
Do While http.readyState <> 4 //查询状态,延时
Yield()
Loop


node = http.responseXML.selectSingleNode("//MedicalServiceXmlResult")
if isnull(node) then 
		is_error = "返回报文无效!"
		return -1
end if 

//读取XML节点数据------------------------------------------------------------------- 
is_result  = string(node.text );  
http.DisconnectObject() 
Destroy http

if(is_result = "") then 
	is_error = "返回报文无效!"
	return -1 
end if 

return 0 
 

powerbuilder9.0真是一个好东东,非常的强大,超级好用啊。

猜你喜欢

转载自blog.csdn.net/aasmfox/article/details/90030292