Envelopexmlns:
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>
<LoginByAccountResponsexmlns="http:
//tempuri.org/">
<LoginByAccountResult>string</LoginByAccountResult>
</LoginByAccountResponse>
</soap:
Body>
</soap:
Envelope>
这是与刚才SOAP请求示例所对应的SOAP响应示例,在成功发送请求后,就可以查看该响应:
Ifxmlhttp.Status=200Then
SetxmlDOC=server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
xmlStr=xmlDOC.xml
SetxmlDOC=nothing
xmlStr=Replace(xmlStr,"<","<")
xmlStr=Replace(xmlStr,">",">")
Response.writexmlStr
Else
Response.Writexmlhttp.Status&""
Response.Writexmlhttp.StatusText
Endif
请求正确则给出完整响应,请求不正确(如账号,密码不对)响应的内容就会信息不完整.
取出响应里的数据,如下:
Ifxmlhttp.Status=200Then
SetxmlDOC=server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
Response.WritexmlDOC.documentElement.selectNodes("//LoginByAccountResult")(0).text‘显示节点为LoginByAccountResult的数据(有编码则要解码)
SetxmlDOC=nothing
Else
Response.Writexmlhttp.Status&""
Response.Writexmlhttp.StatusText
Endif
显示某节点各个属性和数据的FUNCTION:
Functionshowallnode(rootname,myxmlDOC)'望大家不断完鄯2005-1-9writedby844
ifrootname<>""then
setnodeobj=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"")'当前结点对像
nodeAttributelen=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"").attributes.length'当前结点属性数
returnstring=returnstring&"<BR>节点名称:
"&rootname
ifnodeobj.text<>""then
returnstring=returnstring&"<BR>节点的文本:
("&nodeobj.text&")"
endif
returnstring=returnstring&"<BR>{<BR>"
ifnodeAttributelen<>0then
returnstring=returnstring&"<BR>属性数有"&nodeAttributelen&"个,分别是:
"
endif
fori=0tonodeAttributelen-1
returnstring=returnstring&"<li>"&nodeobj.attributes(i).Name&":
"&nodeobj.getAttribute(nodeobj.attributes(i).Name)&"</li>"
next
ifnodeobj.childNodes.Length<>0then
ifnodeobj.hasChildNodes()andlcase(nodeobj.childNodes.item(0).nodeName)<>"#text"then'是否有子节点
setchildnodeobj=nodeobj.childNodes
childnodelen=nodeobj.childNodes.Length
returnstring=returnstring&"<BR><BR>有"&childnodelen&"个子节点;<BR>分别是:
"
fori=0tochildnodelen-1
returnstring=returnstring&"<li>"&childnodeobj.item(i).nodeName&"</li>"
next
endif
endif
returnstring=returnstring&"<BR>}<BR>"
response.writereturnstring
setnodeobj=nothing
endif
EndFunction
可以这样用:
Ifxmlhttp.Status=200Then
SetxmlDOC=server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
showallnode"LoginByAccountResponse",xmlDOC’调用SHOWALLNODE
SetxmlDOC=nothing
Else
Response.Writexmlhttp.Status&""
Response.Writexmlhttp.StatusText
Endif
二.POST请求示例
HTTPPOST
下面是一个HTTPPOST请求示例。
所显示的占位符需要由实际值替换。
POST/WebService1/UserSignOn.asmx/LoginByAccountHTTP/1.1
Host:
192.100.100.81
Content-Type:
application/x-www-form-urlencoded
Content-Length:
length
username=string&password=string
构造POST请求:
<%
url="http:
//192.100.100.81/WebService1/UserSignOn.asmx/LoginByAccount"
SoapRequest="username="&username&"&password="&password
Setxmlhttp=server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open"POST",url,false
xmlhttp.setRequestHeader"Content-Type","application/x-www-form-urlencoded"’注意
xmlhttp.setRequestHeader"HOST","192.100.100.81"
xmlhttp.setRequestHeader"Content-Length",LEN(SoapRequest)
xmlhttp.Send(SoapRequest)
‘这样就利用XMLHTTP成功发送了与HTTPPOST示例所符的POST请求.
‘检测一下是否成功:
Response.Writexmlhttp.Status&””
Response.Writexmlhttp.StatusText
Setxmlhttp=Nothing
%>
如果成功会显示200ok,不成功会显示500内部服务器错误?
Connection:
keep-alive.
成功后就可以利用WEBSERVICE的响应,如下:
HTTPPOST
下面是一个HTTPPOST响应示例。
所显示的占位符需要由实际值替换。
HTTP/1.1200OK
Content-Type:
text/xml;charset=utf-8
Content-Length:
length
<?
xmlversion="1.0"encoding="utf-8"?
>
<stringxmlns="http:
//tempuri.org/">string</string>
显示:
Ifxmlhttp.Status=200Then
SetxmlDOC=server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
showallnode"string",xmlDOC'调用SHOWALLNODE
SetxmlDOC=nothing
Else
Response.Writexmlhttp.Status&""
Response.Writexmlhttp.StatusText