2012-04-25 34 views
4

我在下面的鏈接web服務: http://abc.com/asmx化妝請求通過SOAP的web服務,並得到響應傳統的ASP

我已經提出的要求使用web服務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.

你能告訴我爲什麼我得到這個錯誤是什麼解決它。

+0

同樣的問題在五個小時內三次? – BradBrening 2012-04-25 13:04:37

+0

反覆提問就像是反覆要求降低價格,不是嗎?請只提問一次。 – halfer 2012-04-25 22:41:49

回答

3

是:

你所得到的500錯誤(「期待白色空間」)的原因是你的消息是畸形的。在xml消息中有多個xmlns聲明,並且由於您的vbscript中存在一個錯誤,它們之間沒有空間。結果是無效的XML,並且服務器正在返回錯誤。

另外:

  • 你實際上並不需要前綴在您的郵件envxsd的命名空間聲明。他們從不使用。
  • 你也不需要soap前綴。您可以設置默認的XML名稱空間。
  • 您可以將單引號用於xmlns聲明。這可以使代碼更具可讀性。
  • 您可以在xml消息中插入換行符和空格。這也可以使代碼更具可讀性,特別是出站消息的代碼。

使用這些建議的修改,下面是一些代碼,正常工作:

Dim msg, strStatus, strRetVal, 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", postUrl, false 
xmlHTTP.setRequestHeader "Content-Type", "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,然後我得到一個合理的前瞻性反應。

+0

非常感謝你 – Rash 2012-04-26 05:23:33

+0

請你批准我的編輯,因爲我曾經在帖子中偶然使用過一些活躍的網址? – Rash 2012-04-26 06:03:21

+0

您的編輯已完成。 – Cheeso 2012-04-26 13:12:45

相關問題