2009-05-29 82 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方法和一个同步请求?