WEB客户端用ASP实现WEB服务的小例

来源:互联网 发布:防sql注入是什么意思 编辑:程序博客网 时间:2024/06/06 05:33
The following snippet demonstrate how to use ASP to invoke a web service from remote server:
<%
Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")
Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")
'The following line indicate the WebService we will use.
' It takes 2 parameters as input and output their sum,i.e.
'a simple addition online caculator.
strWebserviceURL = "http://localhost/WebService/Service1.asmx/Add"
'setup parameters and their values
strRequest = "a=15&b=26"
objHTTP.Open "POST", strWebserviceURL, False
'Setup Content-Type
objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.Send(strRequest)
bOK = xmlDOC.load(objHTTP.responseXML)
'Check http status
if objHTTP.Status=200 then
xmlStr = xmlDOC.xml
xmlStr = Replace(xmlStr,"&lt;","<",1,-1,1)
xmlStr = Replace(xmlStr,"&gt;",">",1,-1,1)
Response.Write xmlStr
else
Response.Write objHTTP.Statu & "<br>"
Response.Write objHTTP.StatusText
end if
%>
原创粉丝点击