我在以下链接上有webservices:
http://abc.com/asmx
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)
resp=Error trying to get data from the store. Technical description: The remote name Could not be resolved: ‘www.abc.com’