惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - 花光月影

【转】如何通过mdf文件还原数据库的两种方法 PowerDesign的使用技巧 [转贴]SQL Server用户连接的管理 [转]程序设计中的感悟 几个开源的PORTAL sql2000中修改表的所有者的存储过程 [转]如何让你的SQL运行快起来,希望有所帮助 影响SQLSERVER的性能的一些指标 久不见矣 程序中无法获得Request.ServerVariables("HTTP_REFERER")的值,寻求解决方法~~~~ 农历年底大家都很忙吗? 数据库的安全策略 SQL 事件探查器术语 SQL2000滴系统存储过程--sp_changeobjectowner(更改当前数据库中对象的所有者) SQL学习笔记----SQL2000中的角色及功能 .net中,如何获得活动目录(AD)上的密码失效时间? SQL数据库的事务日志意外增大或充满的处理方法 Sql Server数据库的备份和恢复措施 ASP调用WebServices的方法?
ASP调用.net的webservices的实现方法
花光月影 · 2005-10-12 · via 博客园 - 花光月影

一.请求过程
下面是一个 SOAP 请求示例。所显示的占位符需要由实际值替换。

POST /WebService1/UserSignOn.asmx HTTP/1.1
Host: 
192.100.100.81
Content
-Type: text/xml; charset=utf-8
Content
-Length: length
SOAPAction: 
"http://tempuri.org/LoginByAccount"

<?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>
<LoginByAccount xmlns="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
="<?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>"& _
"<LoginByAccount xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _
"<username>"&username&"</username>"& _
"<password>"&password&"</password>"& _
"</LoginByAccount>"& _
"</soap:Body>"& _
"</soap:Envelope>"
Set xmlhttp 
= 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.Write xmlhttp.Status
&&nbsp;”
Response.Write xmlhttp.StatusText
Set xmlhttp 
= Nothing
%>

<%
url = "
http://192.100.100.81/WebService1/UserSignOn.asmx"
SoapRequest=""& _
"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)&">"& _
""& _
"http://tempuri.org/"&CHR(34)&">"& _
""&username&""& _
""&password&""& _
"
"& _
"
"& _
"
"

Set xmlhttp = 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.Write xmlhttp.Status&” ”
Response.Write xmlhttp.StatusText
Set xmlhttp = Nothing
%>
<%
url = "http://192.100.100.81/WebService1/UserSignOn.asmx"

SoapRequest=""& _
"

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)&">"& _
""& _
"http://tempuri.org/"&CHR(34)&">"& _
""&username&""& _
""&password&""& _
"
"& _
"
"& _
"
"Set xmlhttp = 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.Write xmlhttp.Status&” ”
Response.Write xmlhttp.StatusText
Set xmlhttp = Nothing
%>

如果成功会显示200 ok,不成功会显示 500 内部服务器错误? Connection: keep-alive .
成功后就可以利用WEBSERVICE的响应,如下:
二.响应过程
下面是一个 SOAP 响应示例。所显示的占位符需要由实际值替换。

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>
<LoginByAccountResponse xmlns="http://tempuri.org/">
<LoginByAccountResult>string</LoginByAccountResult>
</LoginByAccountResponse>
</soap:Body>
</soap:Envelope>


这是与刚才SOAP请求示例所对应的SOAP响应示例,在成功发送请求后,就可以查看该响应 :

If xmlhttp.Status = 200 Then
   Set xmlDOC 
=server.CreateObject("MSXML.DOMDocument")
   xmlDOC.load(xmlhttp.responseXML)
   xmlStr 
= xmlDOC.xml
   Set xmlDOC
=nothing
   xmlStr 
= Replace(xmlStr,"<","&lt;")
   xmlStr 
= Replace(xmlStr,">","&gt;")
   Response.write xmlStr 
Else
   Response.Write xmlhttp.Status
&"&nbsp;"
   Response.Write xmlhttp.StatusText
End If


请求正确则给出完整响应,请求不正确(如账号,密码不对)响应的内容就会信息不完整.
取出响应里的数据,如下:

If xmlhttp.Status = 200 Then
  Set xmlDOC 
= server.CreateObject("MSXML.DOMDocument")
  xmlDOC.load(xmlhttp.responseXML)
  Response.Write   xmlDOC.documentElement.selectNodes(
"//LoginByAccountResult")(0).text 
   ‘显示节点为LoginByAccountResult的数据(有编码则要解码)
  Set xmlDOC 
= nothing
Else
  Response.Write xmlhttp.Status
&"&nbsp;"
  Response.Write xmlhttp.StatusText
End 
If


我做的实例:

         '请求过程 
           url 
= "http://172.16.0.0/web/loginuser.asmx" 
         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>" & _ 
         
"<CheckUser xmlns=" & Chr(34& "http://tempuri.org/" & Chr(34& ">" & _ 
         
"<UserId>" & userid & "</UserId>" & _ 
         
"<PassWord>" & password & "</PassWord>" & _ 
         
"</CheckUser>" & _ 
         
"</soap:Body>" & _ 
         
"</soap:Envelope>" 
         Set xmlhttp 
= CreateObject("Msxml2.XMLHTTP"
         xmlhttp.Open 
"POST", url, False 
         xmlhttp.setRequestHeader 
"Content-Type""text/xml;charset=utf-8" 
         xmlhttp.setRequestHeader 
"HOST""localhost" 
         xmlhttp.setRequestHeader 
"Content-Length", Len(SoapRequest) 
         xmlhttp.setRequestHeader 
"SOAPAction""http://tempuri.org/CheckUser" 
         xmlhttp.Send (SoapRequest)
         
'Response.Write xmlhttp.Status &"&nbsp;" 
         'Response.Write xmlhttp.StatusText
            
            '响应过程 

         If xmlhttp.Status = 200 Then 
            Set xmlDOC 
= CreateObject("MSXML.DOMDocument"
            xmlDOC.Load (xmlhttp.responseXML) 
            
'Response.Write xmlDOC.documentElement.selectNodes("//CheckUserResult")(0).text 
            CheckUserCorrect = xmlDOC.documentElement.selectNodes("//CheckUserResult")(0).Text 
            Set xmlDOC 
= Nothing 
         Else 
            CheckUserCorrect 
= xmlhttp.Status & ";" & xmlhttp.StatusText & ";" 
         End If 

posted on 2005-10-12 21:33  花光月影  阅读(976)  评论()    收藏  举报