views:

83

answers:

1

Hi,

I have been tasked with obtaining a response from a SOAP request, using classic asp. The request is about as basic as it gets - I just need to fire off 3 parameters to a web service URL and write out the response (which is in simple plain text format). I've checked the service using a couple of SOAP testing utilities and it outputs the response fine.

I've also read about 10 different tutorials on consuming SOAP feeds in classic ASP, but none of them seem to work at all.

The latest one I'm trying has given me the following code:

<%
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", "http://www.webservicehost.co.uk/B2bservice.asmx?wsdl", False 

oXmlHTTP.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8" 
oXmlHTTP.setRequestHeader "SOAPAction", "http://ourNameSpace/ourFunction"

SOAPRequest = _
  "<?xml version=""1.0"" encoding=""utf-8""?>" &_
  "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""&gt;" &_
    "<soap12:Body>" &_
      "<ourFunction xmlns=""http://ourNameSpace/""&gt;" &_
        "<Ccode>OurCode</Ccode>" &_
        "<Pword>1d2s45a</Pword>" &_
        "<OrderNo>9876</OrderNo>" &_
      "</ourFunction>" &_
    "</soap12:Body>" &_
  "</soap12:Envelope>"
oXmlHTTP.send SOAPRequest

response.write oXmlHTTP.responseText
%>

I have all the correct values for the POST URL, the Ccode, Pword and OrderNo variables, but have no idea what to use for the "SoapAction" or values. As a result, when I run the page I just get an error:

soap:SenderUnable to handle request without a valid action parameter. Please supply a valid soap action.

Can anyone suggest what to use for the SoapAction and ourFunction xmlns values?

Many thanks for any pointers...

+1  A: 

your code should work ok with a few changes

<%
    Response.Write "<br>START<hr>"

    Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
    oXmlHTTP.Open "POST", "http://www.crusaderb2b.co.uk/b2bservice.asmx", False 

    oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
    oXmlHTTP.setRequestHeader "SOAPAction", "http://crusaderb2b.co.uk/TrackingId"

    SOAPRequest = _
      "<?xml version=""1.0"" encoding=""utf-8""?>" &_
      "<soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""&gt;" &_
        "<soap12:Body>" &_
          "<ourFunction xmlns=""http://ourNameSpace/""&gt;" &_
            "<Ccode>OurCode</Ccode>" &_
            "<Pword>1d2s45a</Pword>" &_
            "<OrderNo>9876</OrderNo>" &_
          "</ourFunction>" &_
        "</soap12:Body>" &_
      "</soap12:Envelope>"

    oXmlHTTP.send SOAPRequest    
    Response.Write oXmlHTTP.responseText

    Response.Write "<br>END<hr>"
%>

changes are

  • remove ?wdsl
  • change content type
  • method call needs to be the same server of the webservice as it's the method name

added

I changed the code as you provided the Web Service. All you need you have in the service page as:

alt text

original image here

answer with the code above:

alt text

balexandre
Thanks Balexandre, this gets me further. I now get an error saying: "soap:ClientServer did not recognize the value of HTTP Header SOAPAction: http:// www.webservicehost.co.uk/ B2bservice." (without spaces - I just added those to prevent this editor parsing the URL) I'm not sure what the method name is/should be?
Dan
what is the correct service URL and call method? so I can give you a live example
balexandre
you can see here http://stackoverflow.com/editing-help how to use the Edit Boxes, for your example, just wrap it with the backtick
balexandre
I know the web service URL, but have no idea what the call method is. Is that something I'd need to contact the SOAP feed providers for? Sorry if this is a stupid question, this is just very new to me.
Dan
the WDSL will tell you all about that, what methods exist and what do you need to pass to each other, if the webservice was made in .NET the .asmx page will have something like this: http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx so you can click on every `method` and see what do you need to pass and what will you receive. That's what WDSL all about. **To use a Web Service**, you need to know the end point (URL) and the Method to use, if doing all by `hand` like you are doing, you also need to know what to send and what to expect from the server upon receive the answer.
balexandre
The webservice documentation is here: http://www.crusaderb2b.co.uk/b2bservice.asmx?op=TrackingId. I've tried changing the asp code accordingly, but still get an error: soap:ClientServer did not recognize the value of HTTP Header SOAPAction: <http://www.crusaderb2b.co.uk/B2bservice>. Any ideas greatly appreciated, thanks!
Dan
added the correct code to the answer as you provided the Web Service, as well an image explaining what goes where.
balexandre
Brilliant, that is so helpful, thanks. I now get the same as you. Trouble is, when I use the live credentials (customer code, password and order number) I still get the same ("User login incorrect") - even though I know they're the right details. I even tested with soapclient.com and they work fine, but here, sadly not. Do you have any idea why this might be?
Dan
without the correct credentials I cant help.
balexandre
btw, if the answer helps, you should upvote it !
balexandre
That's my issue now, I have the correct credentials (as proven by the test on soapclient.com) but when I run this script it always tells me the credentials are wrong. The web service provider swears they're correct too, so it has to be a fault with my code somewhere. By the way, I can't vote up as I don't have a reputation of 15 apparently. I would love to vote your answer up as it has been very useful - so until I'm able to vote, please just accept my sincere thanks.
Dan
you can set the answer as the correct one for your question, the green confirmation icon below the vote count on the answer.Use Fiddler to check what are you passing to them, so you can verify if you have an encoding problem that is changing the the chars, once again, without the valid credentials I can't help further.
balexandre