views:

829

answers:

2

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?

A: 

This article 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. Please answer with related materials.

C. Ross
This is not an answer, you should add this supplementary info to your question and delete this answer.
AnthonyWJones
How is this not an answer? It SOLVED MY PROBLEM. What other criteria for being answer is there?
C. Ross
The "Please answer with related materials" sentence made it appear as if some other answer was still needed.
AnthonyWJones
I wanted exactly what you posted, additional info about what i should (and shouldn't) be doing.
C. Ross
+1  A: 

Your code is attempting to set the Host header itself. You should not be doing this.

ServerXMLHTTP will do this for you drawing the host string from the URL provided. By attempting to add it yourself you are corrupting an important criteria for the HTTP protocol. Host is the most fundemental header in the 1.1 protocol, it is the only header that must be present in a 1.1 request.

I'm not sure why you are using an asynchronous request and WaitForResponse just to detect a timeout. Why not use the setTimeouts method and a synchronous request?

AnthonyWJones
Thanks on the Host note. As far as the async goes, I'm just keeping existing functionality of showing a progress bar as long as it's not loaded.
C. Ross
Fair enough but be warned, async WinHTTP inside ASP can be a bit fragile in my experience.
AnthonyWJones
That's fair. I find ASP in IIS 6 can be fragile in general, thanks for the great info.
C. Ross