小记asp调用webService

 最近在研究一个机票数据网站,用httpwatch分析得知,数据来源于一个webservice接口,用.net编写的。

 

在网上找了不少关于如何调用的文章 总是返回500错误。无奈之下自己编写一个webservice接口,用例程调用顺利通过返回200,经过一番对比之后发现时没有注意到webservice得命名空间!

 

<html><head><meta http-equiv="content-type" content="text/html; charset=gbk"><title>webservice</title>
<%
url = "webservice接口url"

depAirportCode = "PEK"
arrAirportCode = "SHA"
depDateStr = "2009-08-16"
userName = "用户名"

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>"& _
"<WebSiteQueryAirlineVacants xmlns="&CHR(34)&"命名空间/"&CHR(34)&">"& _
"<depAirportCode>"&depAirportCode&"</depAirportCode>"& _
"<arrAirportCode>"&arrAirportCode&"</arrAirportCode>"& _
"<depDateStr>"&depDateStr&"</depDateStr>"& _
"<userName>"&userName&"</userName>"& _
"</WebSiteQueryAirlineVacants>"& _
"</soap:Body>"& _
"</soap:Envelope>"

'response.write(SoapRequest) 
'response.end()

Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST","主机域名或ip"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
'一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.setRequestHeader "SOAPAction", "命名空间/WebSiteQueryAirlineVacants" 

xmlhttp.Send(SoapRequest)
'这样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.
'检测一下是否成功:
'Response.Write xmlhttp.Status&"&nbsp;"
'Response.Write xmlhttp.StatusText
'Response.Write xmlhttp.responseText

bOK = xmlDOC.load(xmlhttp.responseXML)
xmlStr = xmlDOC.xml
Response.Write(xmlStr)

Set xmlhttp = Nothing
Set xmlDOC = Nothing

%>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值