本事例是asp调用webservice接口,并获取返回的xml数据及解析!
<!--#include file="conn.asp"-->
<!--#include file ="md532.asp"-->
<!--#include file="SYS_INCLUDE_HTML.ASP"-->
<%
Response.Write "测试时间:"&now()&"<br>"
dim url,SOAPAction,HOST
url="http://192.168.17.71/KDWebservice/KDService.asmx?op=CreateCust"//webserbice地址 =号后面是接口的方法
Host="192.168.17.71"//ip地址
SOAPAction="http://tempuri.org/CreateCust"//把CreateCust替换你的方法
dim stringJS
custno=request("custno")
key="16394"
strtoken=custno&key
token=md5(strtoken,32,0)
//====获取单据表头信息
set rs=server.createobject("adodb.recordset")
sql ="select * from [customer] where custno='"&custno&"'"
rs.open sql,conn,1,1
if not rs.eof then
fCustNo=rs("custno")
fCustName=rs("cmingcheng")
end if
rs.close
stringJS="{'token':'"&token&"','head':{'fCustNo':'"&fCustNo&"','fCustName':'"&fCustName&"'}}"//这是我获取数据拼接的json ,可以替换你自己的json
Response.Write stringJS &"<br>"
SoapRequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<CreateCust xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _//把CreateCust替换你的方法
"<json>"&stringJS&"</json>"& _
"</CreateCust>"& _//把CreateCust替换你的方法
"</soap:Body>"& _
"</soap:Envelope>"
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type","text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST",Host
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction",SOAPAction
// ‘一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
//‘这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
//‘检测一下是否成功:
Response.Write "Status:"&xmlhttp.Status&"<BR>"
Response.Write "StatusText:"&xmlhttp.StatusText&"<BR>"
if xmlhttp.status = 200 then
set xmldoc = server.createobject("msxml2.domdocument")
xmldoc.load(xmlhttp.responsexml)
//xmldoc是接收了webservice返回的xml内容,如果webservice返回的不是xml,就用xmlhttp.responsetext
objNodes = xmldoc.getElementsByTagName("root/msgType")
Response.Write "Status:"&objNodes &"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgType")(0).text //解析xml root 第一个节点 msgType 第二个节点
Response.Write "msgType:"&sendMessageByPhone&"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgstring")(0).text
Response.Write "msgstring:"&sendMessageByPhone&"<BR>"
else
Response.Write "调用webservice失败"
end if
Set xmlhttp = Nothing
%>
<!--#include file="conn.asp"-->
<!--#include file ="md532.asp"-->
<!--#include file="SYS_INCLUDE_HTML.ASP"-->
<%
Response.Write "测试时间:"&now()&"<br>"
dim url,SOAPAction,HOST
url="http://192.168.17.71/KDWebservice/KDService.asmx?op=CreateCust"//webserbice地址 =号后面是接口的方法
Host="192.168.17.71"//ip地址
SOAPAction="http://tempuri.org/CreateCust"//把CreateCust替换你的方法
dim stringJS
custno=request("custno")
key="16394"
strtoken=custno&key
token=md5(strtoken,32,0)
//====获取单据表头信息
set rs=server.createobject("adodb.recordset")
sql ="select * from [customer] where custno='"&custno&"'"
rs.open sql,conn,1,1
if not rs.eof then
fCustNo=rs("custno")
fCustName=rs("cmingcheng")
end if
rs.close
stringJS="{'token':'"&token&"','head':{'fCustNo':'"&fCustNo&"','fCustName':'"&fCustName&"'}}"//这是我获取数据拼接的json ,可以替换你自己的json
Response.Write stringJS &"<br>"
SoapRequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<CreateCust xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _//把CreateCust替换你的方法
"<json>"&stringJS&"</json>"& _
"</CreateCust>"& _//把CreateCust替换你的方法
"</soap:Body>"& _
"</soap:Envelope>"
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type","text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST",Host
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction",SOAPAction
// ‘一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
//‘这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
//‘检测一下是否成功:
Response.Write "Status:"&xmlhttp.Status&"<BR>"
Response.Write "StatusText:"&xmlhttp.StatusText&"<BR>"
if xmlhttp.status = 200 then
set xmldoc = server.createobject("msxml2.domdocument")
xmldoc.load(xmlhttp.responsexml)
//xmldoc是接收了webservice返回的xml内容,如果webservice返回的不是xml,就用xmlhttp.responsetext
objNodes = xmldoc.getElementsByTagName("root/msgType")
Response.Write "Status:"&objNodes &"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgType")(0).text //解析xml root 第一个节点 msgType 第二个节点
Response.Write "msgType:"&sendMessageByPhone&"<BR>"
sendMessageByPhone=xmldoc.documentElement.selectNodes("//root//msgstring")(0).text
Response.Write "msgstring:"&sendMessageByPhone&"<BR>"
else
Response.Write "调用webservice失败"
end if
Set xmlhttp = Nothing
%>