专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web Service

ASP 调用Web Service 异常

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
ASP 调用Web Service 错误
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"
倒数第六行
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: