2009-05-29 83 views
1

我試圖從ASP.NET web服務得到響應而不使用get參數。我有以下代碼。Asp經典呼籲web服務與SOAP請求

strBarcode = "ABC123 
strURL ="http://serverName/BarcodeGenerator.asmx" 
Set xmlReq = Server.CreateObject("Msxml2.DOMDocument.3.0") 
Set xmlResp = Server.CreateObject("Msxml2.DOMDocument.3.0") 
Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP") 


xmlReq.async = false 
strXML = CStr(CreateRequest(strBarcode)) 

xmlReq.loadXML(CStr(strXML)) 

//Open, async 

httpReq.open "POST", CStr(strURL), true 

httpReq.setRequestHeader "Host", "serverName" 
httpReq.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
httpReq.setRequestHeader "SOAPAction", "http://tempuri.org/GetBarcode" 

httpReq.send(xmlReq) 



strDone = "0" 
bTimeout = false 
dStart = Now() 
dEnd = Now() 
lCounter = 0 
lCounterPrev = -1 
intStatus = 0 
Do while intStatus <> 4 and (Not bTimeout) 
    dEnd = Now() 
    lCounter = DateDiff("s",dStart,dEnd) 

    if lCounter > 30 then bTimeout = True  
    %>. <%  
    'Wait a second 
    httpReq.waitForResponse 1000 
    intStatus = httpReq.readyState 
Loop 

If httpReq.readyState = 4 Then 
    bTimeout = false 
    Set xmlResp = httpReq.responseXML 
    %> 
    Status: <%=httpReq.statusText%><BR> 
    Response: <%=httpReq.responseText%> <BR><BR> 
    <% 
    Set nodes = xmlResp.getElementsByTagName("GetBarcodeResult") 
    If (nodes is nothing) THen 
    %>Nodes is NULL<BR><% 
    Else 
    %>Number of Nodes: <%=nodes.length%><% 
    End IF 
    Set node = nodes(0) 
    url = node.nodeValue 
End If 

狀態是

狀態:錯誤的請求

和響應是

響應:錯誤的請求(無效主機名)

我在做什麼錯了?

回答

1

這個article解釋得最好,但基本上,由於IIS配置服務器無法找到自己(經典的ASP和Web服務託管在同一臺服務器上)。代碼沒有問題。請用相關材料回答。

+0

這不是一個答案,你應該添加這個補充信息到你的問題,並刪除這個答案。 – AnthonyWJones 2009-05-31 20:21:28

+0

這不是一個答案?它解決了我的問題。還有哪些其他的答案標準呢? – 2009-06-01 12:15:43

1

您的代碼正在嘗試設置主機頭本身。你不應該這樣做。

ServerXMLHTTP將爲您從所提供的URL中繪製主機字符串。通過嘗試自己添加它會破壞HTTP協議的重要標準。主機是1.1協議中最具有趣味性的標頭,它是1.1請求中必須存在的唯一標頭。

我不知道你爲什麼使用異步請求和WaitForResponse來檢測超時。爲什麼不使用setTimeouts方法和一個同步請求?