Sending a 'application/soap+xml' SOAP request using Classic ASP

Simon picture Simon · Jan 7, 2010 · Viewed 57.1k times · Source

Any help with this would be appreciated; I've been at it for a few days now.

Below is the code that I've got so far; unfortunatly when I run it I get a HTTP 415 error; Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'.

I have to send the content-type of application/soap+xml as this is the only type that the web service allows; and I have to do it in classic ASP.

I've tried changing the 'send' line to "objRequest.send objXMLDoc.XML" but this then gives me a HTTP 400 Bad Request error.


strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"

Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False

objRequest.setRequestHeader "Content-Type", "application/soap+xml"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"

Set objXMLDoc = Server.createobject("MSXML2.DOMDocument.3.0")
objXMLDoc.loadXml strXmlToSend
objRequest.send objXMLDoc
set objXMLDoc = nothing

Answer

Eric Petroelje picture Eric Petroelje · Jan 7, 2010

Here's what I've used successfully in the past:

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xmlhttp.open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
    xmlhttp.setRequestHeader "SOAPAction", "http://www.mydomain.com/myaction" 
    xmlhttp.send postdata
    xml = xmlhttp.responseText