views:

1233

answers:

3

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.

Any help greatly appreciated.

Regards,


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
+1  A: 

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
Eric Petroelje
Hi, thanks for the answer. Unfortuantly I think the problem is with formating the data that is sent, it always views it as 'text/xml' even if I specify 'application/soap+xml'.Regards
Simon
@Simon - if that's the case, you'll want to have a look at what is being posted. As shahkalpesh suggested, try fiddler to see what is being posted from your page vs. what is posted if you use a web service testing tool such as SoapUI. It could be that you are missing some important XML (such as the soap envelope for example)
Eric Petroelje
A: 

When you pass an XML DOM ot the send method the Content-Type is always set to "text/xml".

If you want to control the content type then you must pass a string. Don't bother loading the XML string into a DOM only to call the xml property since that may change the content of the xml declaration. BTW what does the xml declaration look like in the XML string and are you certain that the xml is correct? The encoding on the xml declare if present should say "UTF-8".

Don't send a header CharSet it means nothing, CharSet is an attribute of the Content-Type header.

Don't use XMLHTTP from inside ASP its not safe.

Hence your code ought to look like this:-

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

Set objRequest = Server.Createobject("MSXML2.ServerXMLHTTP.3.0") 
objRequest.open "POST", webserviceurl, False 

objRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=UTF-8" 
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate" 
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate" 

objRequest.send strXmlToSend 

Not sure about that "action" header either looks superflous to me. Perhaps this will still fail in some way but it shouldn't complain about the Content-Type header anymore.

AnthonyWJones
A: 

Hi All,

Thanks for your help; it turns out that the SOAP message I was posting was incorrectly formatted.

I used a tool here: http://soapclient.com/soaptest.html and was able to check what the web service was expecting and make sure mine was tailored to it.

Regards,

Simon.

Simon