小记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

%>

 

 

你可能感兴趣的:(xml,webservice,asp.net,asp,SOAP)