微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

web-services – 通过soap向webservice发出请求并获得经典的asp响应

我在以下链接上有webservices:
http://abc.com/asmx

我已经使用以下代码向webservice getcustomers提出了请求:

<%
DIM PostData,strStatus,strRetVal,postUrl

PostData = _
"<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap:Envelope xmlns:env=""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>" &_
  " <getCustomer xmlns=""http://3dcart.com/"">" &_
  "<storeUrl>www.abc.stores.com/</storeUrl>" &_
  "<userKey>sdfsf</userKey>" &_
  "<batchSize>1</batchSize>" &_
  "<startNum>1</startNum>" &_
   "<customersFilter>firstname=John</customersFilter>"&_ 
    "<callBackURL></callBackURL>"&_ 
    "</getCustomer>"&_
     "</soap:Body>" &_
"</soap:Envelope>"

response.write("req=" & Server.HTMLEncode(PostData) & "<br/>len=" & len(PostData))
postUrl = "http://abc.com/cart.asmx?op=getCustomer"
Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlHTTP.open "POST",postUrl,false
xmlHTTP.setRequestHeader "Content-Type","text/xml; charset=utf-8" 
'xmlHTTP.setRequestHeader "SOAPAction","http://AvailReceive/AvailRq"
xmlHTTP.send PostData
strStatus = xmlHTTP.Status
strRetval = xmlHTTP.responseText
set xmlHTTP = nothing
response.write("<br/>") 
response.write("status=" & strStatus & "<br/>resp=" & strRetval)
%>

但我得到错误
resp = soap:ReceiverServer无法处理请求. —> ‘http’是一个意外的令牌.期待白色空间.第1行,第163位.

你能告诉我为什么我得到这个错误它的解决方案是什么.

解决方法

是:

您收到500错误(“期望空白”)的原因是您的邮件格式错误.您在xml消息中有几个xmlns声明,并且由于您的vbscript中存在错误,它们之间没有空格.结果是无效的XML,并且服务器因此而返回错误.

也:

>实际上,您的消息中实际上不需要前缀env和xsd的名称空间声明.他们从未使用过.
>你也不需要肥皂前缀.您只需设置认的XML命名空间即可.
>您可以使用单引号作为xmlns声明.这可以使代码更具可读性.
>您可以在xml消息中插入换行符和空格.这也可以使代码更具可读性,特别是出站消息的代码.

使用这些建议的更改,以下是一些正常工作的代码

Dim msg,postUrl

msg = "<?xml version='1.0' encoding='utf-8'?>" &_
         "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" & VbCrLf &_
         "  <Body>" & VbCrLf &_
         "    <getCustomer xmlns='http://abc.com/'>" & VbCrLf &_
         "      <storeUrl>www.abc.com/</storeUrl>" & VbCrLf &_
         "      <userKey>345</userKey>" & VbCrLf &_
         "      <batchSize>1</batchSize>" & VbCrLf &_
         "      <startNum>1</startNum>" & VbCrLf &_
         "      <customersFilter>firstname=John</customersFilter>"& VbCrLf &_
         "      <callBackURL></callBackURL>"& VbCrLf &_
         "    </getCustomer>" & VbCrLf &_
         "  </Body>" & VbCrLf &_
         "</Envelope>"

Response.write("req=" & Server.HTMLEncode(msg) & "<br/>len=" & len(msg))

postUrl = "http://abc.com/cart.asmx?op=getCustomer"

Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlHTTP.open "POST","text/xml; charset=utf-8"
'xmlHTTP.setRequestHeader "SOAPAction","http://AvailReceive/AvailRq"
xmlHTTP.send msg

strStatus = xmlHTTP.Status
strRetval = xmlHTTP.responseText
set xmlHTTP = nothing
Response.write("<br/>")
Response.write("status=" & strStatus & "<br/>resp=" & strRetval)

但是……这段代码揭示了.ASMX脚本中的运行时错误.

resp=Error trying to get data from the store. Technical description: The remote name Could not be resolved: ‘www.abc.com’

如果我修改发消息以将主机名指定为abc.com而不是www.abc.com,那么我会得到一个合理的响应.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐