Search code examples
web-servicesasp-classic

Asp Classic Calling webservice with SOAP Request


I'm trying to get a response from a ASP.NET webservice without using the get parameters. I have the following code.

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

The status is

Status: Bad Request

and the response is

Response: Bad Request (Invalid Hostname)

What am I doing wrong?


Solution

  • This article (now via web.archive.org for posterity) explains it best, but basically, due to IIS configuration the server was unable to locate itself (the classic-asp and webservice were hosted on the same server). There are no problems with the code.