ASP如何调用。Net的WebService
2006-04-16 22:25
471 查看
ASP调用.Net的webservice的例子:
假设webservice的地址是http://192.168.0.88/test.asmx 接口是doAdd
下面是WebService的 SOAP 请求和响应示例
POST /test.asmx HTTP/1.1
Host: 192.168.0.88
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.test.com/doAdd"
<?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>
<doAdd xmlns="http://www.test.com">
<sRequest>string</sRequest>
</doAdd>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<doAddResponse xmlns="http://www.test.com">
<doAddResult>string</doAddResult>
</doAddResponse>
</soap:Body>
</soap:Envelope>
下面是ASP页面:test.asp
<%
Dim url,xmlhttp,dom,node,xmlDOC
'根据webservice的测试页,构造不同的soap request
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>"&_
"<queryCardInfo xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"&_
"<nCardID>0</nCardID>"&_
"<nAmt>1</nAmt>"&_
"</queryCardInfo>"&_
"</soap:Body>"&_
"</soap:Envelope>"
url = "http://192.168.0.88/test.asmx?op=doAdd"
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.loadXML(SoapRequest)
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
'SOAPAction这个Header头同样可以在sample中找到
xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/queryCardInfo"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(xmlDOC)
response.write "status = "&xmlhttp.Status&"<br>"
response.write "statustxt = "&xmlhttp.StatusText&"<br>"
response.write "responseText = "&xmlhttp.responseText&"<br>"
If xmlhttp.Status = 200 Then 'ok responseXML
xmlDOC.load(xmlhttp.responseXML)
'response.write "price = "&xmlDOC.getElementsByTagName("PARAMS").item(0).xml&"<br>"
response.Write(xmlDOC.xml)
else
response.write "failed"
end if
%>
假设webservice的地址是http://192.168.0.88/test.asmx 接口是doAdd
下面是WebService的 SOAP 请求和响应示例
POST /test.asmx HTTP/1.1
Host: 192.168.0.88
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.test.com/doAdd"
<?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>
<doAdd xmlns="http://www.test.com">
<sRequest>string</sRequest>
</doAdd>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<doAddResponse xmlns="http://www.test.com">
<doAddResult>string</doAddResult>
</doAddResponse>
</soap:Body>
</soap:Envelope>
下面是ASP页面:test.asp
<%
Dim url,xmlhttp,dom,node,xmlDOC
'根据webservice的测试页,构造不同的soap request
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>"&_
"<queryCardInfo xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"&_
"<nCardID>0</nCardID>"&_
"<nAmt>1</nAmt>"&_
"</queryCardInfo>"&_
"</soap:Body>"&_
"</soap:Envelope>"
url = "http://192.168.0.88/test.asmx?op=doAdd"
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.loadXML(SoapRequest)
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
'SOAPAction这个Header头同样可以在sample中找到
xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/queryCardInfo"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(xmlDOC)
response.write "status = "&xmlhttp.Status&"<br>"
response.write "statustxt = "&xmlhttp.StatusText&"<br>"
response.write "responseText = "&xmlhttp.responseText&"<br>"
If xmlhttp.Status = 200 Then 'ok responseXML
xmlDOC.load(xmlhttp.responseXML)
'response.write "price = "&xmlDOC.getElementsByTagName("PARAMS").item(0).xml&"<br>"
response.Write(xmlDOC.xml)
else
response.write "failed"
end if
%>
相关文章推荐
- ASP如何调用。Net的WebService
- .NET3.5下Asp.net如何异步调用WebService
- ASP.NET如何定时调用WebService服务
- jQuery如何调用ASP.NET的WebService
- asp.net如何调用webservice,如何动态设置webservice引用地址
- Asp.Net Ajax 如何调用WebService
- Asp.NET Core 如何调用WebService的方法
- 如何在ASP.Net Ajax中调用WebService
- ASP.NET如何定时调用WebService服务
- asp.net如何调用 webservice
- 如何动态调用asp.net Webservice
- 如何:确定调用 ASP.NET 网页的方式
- ASP.NET AJAX 中,如何用 JavaScript 调用服务器端的方法?
- 在JavaScript中调用ASP.NET WebService的简单方法
- asp.net调用JAVA的webservice时注意
- ASP.NET中如何调用存储过程
- asp.net 调用带证书的webservice解决办法
- ASP.NET 调用 webservice
- ASP.NET中如何调用存储过程
- ASP.net用法系列:如何从基类调用LINQ/EF类的属性