ASP 调用Web Service 错误
Dim url,host,method,xmlns,soapAction,soapRequest,xmlDocument
host = "www.caohejing.web"
url = "http://www.caohejing.web/webservice/news/Default.asmx"
method = "POST"
xmlns = "http://www.caohejing.com/NewsService/"
soapAction = "http://www.caohejing.com/NewsService/NewsAction"
'xmlDocument = CreateXmlDocument()
xmlDocument="new"
'拼接请求字符串
soapRequest = "<?xml version='1.0' encoding='utf-8'?>"
soapRequest = soapRequest & " <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'> "
soapRequest = soapRequest & " <soap12:Body>"
soapRequest = soapRequest & " <NewsAction xmlns='"& xmlns &"'>"
soapRequest = soapRequest & " <newsXML>"& xmlDocument &"</newsXML>"
'soapRequest = soapRequest & " <newsXML>test msg</newsXML>"
soapRequest = soapRequest & " </NewsAction> "
soapRequest = soapRequest & " </soap12:Body>"
soapRequest = soapRequest & " </soap12:Envelope>"
response.Write(soapRequest)
'创建XMLHttp连接,并传输数据
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST", host
xmlhttp.setRequestHeader "Content-Length",LEN(soapRequest)
xmlhttp.setRequestHeader "SOAPAction", soapAction 'WEBSERVICE的命名空间+ "/" + 调用的方法名称
xmlhttp.Send(SoapRequest)
POST /webservice/news/Default.asmx HTTP/1.1Host: www.caohejing.webContent-Type: text/xml; charset=utf-8Content-Length: lengthSOAPAction: "http://www.caohejing.com/NewsService/NewsAction"<?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> <NewsAction xmlns="http://www.caohejing.com/NewsService/"> <newsXML>string</newsXML> </NewsAction> </soap:Body></soap:Envelope>
xmlhttp.Open "POST",url,false
你把这个url改成 本地的测试地址应该就行了
[解决办法]
CreateXmlDocument() 这个函数拼凑的xml应该需要编码才能加入 原始soap字串中
具体怎么做你可以 使用c#写个客户端调用你的ws 然后用fiddler等监听下请求
我这截获的http post调用的原始请求是:
POST http://192.168.1.10:8088/webservices/appadrs2010/service.asmx/VerifyAccessIdentity HTTP/1.1
Accept: */*
Referer: http://192.168.1.10:8088/webservices/appadrs2010/service.asmx?op=VerifyAccessIdentity
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; Tablet PC 2.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: 192.168.1.10:8088
Content-Length: 137
Connection: Keep-Alive
Pragma: no-cache
sUserName=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E&sPassword=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E