webserviceWord下载.docx
《webserviceWord下载.docx》由会员分享,可在线阅读,更多相关《webserviceWord下载.docx(7页珍藏版)》请在冰豆网上搜索。
![webserviceWord下载.docx](https://file1.bdocx.com/fileroot1/2023-1/27/0e47f477-9a12-488f-9dce-d07de736b1f5/0e47f477-9a12-488f-9dce-d07de736b1f51.gif)
xmlversion="
1.0"
encoding="
utf-8"
?
>
<
soap:
Envelopexmlns:
xsi="
//www.w3.org/2001/XMLSchema-instance"
xmlns:
xsd="
//www.w3.org/2001/XMLSchema"
soap="
//schemas.xmlsoap.org/soap/envelope/"
<soap:
Body>
<LoginByAccountxmlns="
//tempuri.org/"
<username>string</username>
<password>string</password>
</LoginByAccount>
</soap:
Envelope>
为了与WEBSERVICE交互,需要构造一个与上完全相同的SOAP请求:
<%
url="
//192.100.100.81/WebService1/UserSignOn.asmx"
SoapRequest="
&
CHR(34)&
"
>"
_
xmlns:
Body>"
LoginByAccountxmlns="
<username>"
username&
</username>"
<password>"
password&
</password>"
</LoginByAccount>"
Envelope>"
Setxmlhttp=server.CreateObject("
Msxml2.XMLHTTP"
)
xmlhttp.Open"
POST"
url,false
xmlhttp.setRequestHeader"
Content-Type"
"
text/xml;
charset=utf-8"
HOST"
"
192.100.100.81"
Content-Length"
LEN(SoapRequest)
xmlhttp.setRequestHeader"
SOAPAction"
‘一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
‘这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
‘检测一下是否成功:
Response.Writexmlhttp.Status&
””
Response.Writexmlhttp.StatusText
Setxmlhttp=Nothing
%>
如果成功会显示200ok,不成功会显示500内部服务器错误?
Connection:
keep-alive.
成功后就可以利用WEBSERVICE的响应,如下:
SOAP响应示例
下面是一个SOAP响应示例。
HTTP/1.1200OK
<LoginByAccountResponsexmlns="
<LoginByAccountResult>string</LoginByAccountResult>
</LoginByAccountResponse>
这是与刚才SOAP请求示例所对应的SOAP响应示例,在成功发送请求后,就可以查看该响应:
Ifxmlhttp.Status=200Then
SetxmlDOC=server.CreateObject("
MSXML.DOMDocument"
xmlDOC.load(xmlhttp.responseXML)
xmlStr=xmlDOC.xml
SetxmlDOC=nothing
xmlStr=Replace(xmlStr,"
<"
>
Response.writexmlStr
Else
Endif
请求正确则给出完整响应,请求不正确(如账号,密码不对)响应的内容就会信息不完整.
取出响应里的数据,如下:
SetxmlDOC=server.CreateObject("
Response.WritexmlDOC.documentElement.selectNodes("
//LoginByAccountResult"
)(0).text‘显示节点为LoginByAccountResult的数据(有编码则要解码)
SetxmlDOC=nothing
显示某节点各个属性和数据的FUNCTION:
Functionshowallnode(rootname,myxmlDOC)'
望大家不断完鄯2005-1-9writedby844
ifrootname<>"
then
setnodeobj=myxmlDOC.documentElement.selectSingleNode("
//"
rootname&
)'
当前结点对像
nodeAttributelen=myxmlDOC.documentElement.selectSingleNode("
).attributes.length'
当前结点属性数
returnstring=returnstring&
<BR>节点名称:
rootname
ifnodeobj.text<>"
<BR>节点的文本:
("
nodeobj.text&
)"
endif
<BR>{<BR>"
ifnodeAttributelen<>0then
<BR>属性数有"
nodeAttributelen&
个,分别是:
fori=0tonodeAttributelen-1
<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
<BR><BR>有"
childnodelen&
个子节点;
<BR>分别是:
fori=0tochildnodelen-1
childnodeobj.item(i).nodeName&
</li>"
<BR>}<BR>"
response.writereturnstring
setnodeobj=nothing
EndFunction
可以这样用:
xmlDOC.load(xmlhttp.responseXML)
showallnode"
LoginByAccountResponse"
xmlDOC’调用SHOWALLNODE
二.POST请求示例
HTTPPOST
下面是一个HTTPPOST请求示例。
POST/WebService1/UserSignOn.asmx/LoginByAccountHTTP/1.1
application/x-www-form-urlencoded
username=string&
password=string
构造POST请求:
//192.100.100.81/WebService1/UserSignOn.asmx/LoginByAccount"
username="
password="
password
application/x-www-form-urlencoded"
’注意
‘这样就利用XMLHTTP成功发送了与HTTPPOST示例所符的POST请求.
下面是一个HTTPPOST响应示例。
<stringxmlns="
>string</string>
显示:
string"
xmlDOC'
调用SHOWALLNODE