ASP构造SOAP调用WebService

  1. <%
  2. url = "http://localhost/webservice/Service.asmx"
  3. SoapRequest="<?xml version=""1.0"" encoding=""utf-8""?>"& _
  4. "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "& _
  5. "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "& _
  6. "xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""> "& _
  7. "<soap12:Header> "& _ 
  8. "</soap12:Header> "& _ 
  9. "<soap12:Body>"& _
  10. "<loginService xmlns=""http://tempuri.org/""> "& _
  11. "<SYSID>"111"</SYSID> "& _
  12. "</loginService> "& _
  13. "</soap12:Body>"& _
  14. "</soap12:Envelope>"
  15. Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
  16. xmlhttp.Open "POST",url,false
  17. xmlhttp.setRequestHeader "Content-Type""application/soap+xml; charset=utf-8"
  18. xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
  19. xmlhttp.setRequestHeader "SOAPAction""http://tempuri.org/relationService" '一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
  20. xmlhttp.Send(SoapRequest)
  21. '这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
  22. '检测一下是否成功:
  23. 'Response.Write xmlhttp.Status & "<br>"
  24. Response.Write xmlhttp.responsetext
  25. Set xmlhttp = Nothing
  26. %>
  27. 以上代码摘抄自网络,除以上方法外也可以使用MSSOAP.SoapClient30进行调用。
  28. 这段代码的主要意义在于可以了解到WebService的调用,主要是以什么格式发送了什么东西,从而了解到SOAP是什么。
  29. 其实,每一次WebService的调用就是发送类似这么一段XML给服务端,服务端再接收这段XML解析出调用的方法及参数,再返回类似的XML给客户端。
  30. 可在这里http://www.w3school.com.cn/soap/index.asp了解一下有关SOAP的相关知识。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值