- VB code
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)
Web Service 调用的例子
- VB code
POST /webservice/news/Default.asmx HTTP/1.1 Host: www.caohejing.web Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "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>
执行结果:400 Bad Request
------解决方案--------------------
400?
就是不存在这个东西。。。
应该首先去确定一下是不是路径有问题。。
------解决方案--------------------
完全按照下面的 拼凑字符串,然后用xmlhttp发送能行吗?
看你2段代码 ,前面的是soap12:Envelope
------解决方案--------------------
客气了
首先 你asp代码中
url = "http://www.caohejing.web/webservice/news/Default.asmx"
这个地址从我这是打不开的
如果是有其他测试地址,先把这里改过来 ws完整的测试地址
你下面ws的post调用例子里 写的是相对地址POST /webservice/news/Default.asmx HTTP/1.1
------解决方案--------------------
哦
但是你asp代码里的调用地址写的是带域名的
第三行
url = "http://www.caohejing.web/webservice/news/Default.asmx"
倒数第六行