webservice.docx

上传人:b****5 文档编号:8019905 上传时间:2023-01-28 格式:DOCX 页数:7 大小:16.17KB
下载 相关 举报
webservice.docx_第1页
第1页 / 共7页
webservice.docx_第2页
第2页 / 共7页
webservice.docx_第3页
第3页 / 共7页
webservice.docx_第4页
第4页 / 共7页
webservice.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

webservice.docx

《webservice.docx》由会员分享,可在线阅读,更多相关《webservice.docx(7页珍藏版)》请在冰豆网上搜索。

webservice.docx

webservice

1.soap请求方式

2.post请求方式

3.SHOWALLNODE函数(关于节点各属性和数据显示)

一.SOAP请求示例

  下面是一个SOAP请求示例。

所显示的占位符需要由实际值替换。

POST/WebService1/UserSignOn.asmxHTTP/1.1

Host:

192.100.100.81

Content-Type:

text/xml;charset=utf-8

Content-Length:

length

SOAPAction:

"http:

//tempuri.org/LoginByAccount"

<?

xmlversion="1.0"encoding="utf-8"?

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>

<LoginByAccountxmlns="http:

//tempuri.org/">

<username>string</username>

<password>string</password>

</LoginByAccount>

</soap:

Body>

</soap:

Envelope>

  为了与WEBSERVICE交互,需要构造一个与上完全相同的SOAP请求:

<%

url="http:

//192.100.100.81/WebService1/UserSignOn.asmx"

SoapRequest="<?

xmlversion="&CHR(34)&"1.0"&CHR(34)&"encoding="&CHR(34)&"utf-8"&CHR(34)&"?

>"&_

"

Envelopexmlns:

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>"&_

"

//tempuri.org/"&CHR(34)&">"&_

"<username>"&username&"</username>"&_

"<password>"&password&"</password>"&_

"</LoginByAccount>"&_

"</soap:

Body>"&_

"</soap:

Envelope>"

Setxmlhttp=server.CreateObject("Msxml2.XMLHTTP")

xmlhttp.Open"POST",url,false

xmlhttp.setRequestHeader"Content-Type","text/xml;charset=utf-8"

xmlhttp.setRequestHeader"HOST","192.100.100.81"

xmlhttp.setRequestHeader"Content-Length",LEN(SoapRequest)

xmlhttp.setRequestHeader"SOAPAction","http:

//tempuri.org/LoginByAccount"‘一定要与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

Content-Type:

text/xml;charset=utf-8

Content-Length:

length

<?

xmlversion="1.0"encoding="utf-8"?

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 管理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1