关于ASP调用.net WebService 的标准例子
打开WebService地址 可以看到说明,必须注意1.1和1.2版本的SOAP的不同地方。一般出现错误都基本在这些地方。
演示地址自发布之日起30天内保证有效。
http://api.510769.com/Service.asmx?op=AandB
改进版(有兄弟说无法直接应用,其实应用很简单)
<% url = "HTTP://API.510769.COM/Service.asmx" SoapRequest="<?xml version=""1.0"" encoding=""utf-8""?>"&_ "<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/"">"&_ " <soap:Body>"&_ " <AandB xmlns=""HTTP://API.510769.COM/"">"&_ " <a>1</a>"&_ " <b>2</b>"&_ " </AandB>"&_ " </soap:Body>"&_ "</soap:Envelope>" Set xmlDOC =Server.CreateObject("MSXML.DOMDocument") Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP") xmlhttp.Open "POST",url,False xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest) xmlhttp.setRequestHeader "Host","api.510769.com" xmlhttp.setRequestHeader "SOAPAction","HTTP://API.510769.COM/AandB" xmlhttp.Send(SoapRequest) bOK = xmlDOC.load(xmlhttp.responseXML) xmlStr = xmlDOC.xml Set ReStr=xmlDOC.documentElement.selectNodes("//AandBResult") '这就是直接调用 Response.Write(bOK&xmlStr&ReStr(0).text) 'bOK为fasle就是失败了 Set ReStr = Nothing Set xmlhttp = Nothing Set xmlDOC = Nothing %>
代码
<%
Dim url = "HTTP://API.510769.COM/Service.asmx"
Dim SoapRequest="<?xml version=""1.0"" encoding=""utf-8""?>"&_
"<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/"">"&_
" <soap:Body>"&_
" <AandB xmlns=""HTTP://API.510769.COM/"">"&_
" <a>1</a>"&_
" <b>2</b>"&_
" </AandB>"&_
" </soap:Body>"&_
"</soap:Envelope>"
Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,False
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "Host","api.510769.com"
xmlhttp.setRequestHeader "SOAPAction","HTTP://API.510769.COM/AandB"
xmlhttp.Send(SoapRequest)
bOK = xmlDOC.load(xmlhttp.responseXML)
xmlStr = xmlDOC.xml
Response.Write(bOK&xmlStr)'bOK为fasle就是失败了
Set xmlhttp = Nothing
Set xmlDOC = Nothing
%>