views:

118

answers:

2

Hey y'all..

Is there a a quick way to validate SOAP messages? I have seen validator for JSON objects. Is there something like this for SOAP? I am recieveing a 'Bad Request: 400' error response with a AJAX post I am working on. I am not too familiar with SOAP as I typically just pass JSON. Can someone tell me what is wrong with my request or perhaps suggest a good way to debug it myself? Firebug error message is just 'Bad Request: 400' so it doesn't really help a terrible amount.

I would greatful for any insight on this.

Thanks!!

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;&lt;soap:Body&gt;&lt;UpdateAutoChart xmlns='http://somewhere.org/hwconnect/services' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding'&gt;alertid=Test&amp;companytoken=hw&amp;autochart=false&lt;/UpdateAutoChart&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;

This is my POST function:

function doPost(method, body) {
var soapRequest = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ";
soapRequest = soapRequest + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;";
soapRequest = soapRequest + "<soap:Body>"
soapRequest = soapRequest + "<" + method + " xmlns='http://somewhere.org/hwconnect/services' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding'&gt;"; 
soapRequest = soapRequest + body;
soapRequest = soapRequest + "</" + method + ">";
soapRequest = soapRequest + "</soap:Body></soap:Envelope>";
jQuery.noConflict();
jQuery.ajax({
    beforeSend: function(xhrObj) {
        xhrObj.setRequestHeader("Method", "POST");
        xhrObj.setRequestHeader("Content-Type", "text/xml; charset=\"utf-8\";");
        xhrObj.setRequestHeader("SOAPAction", "http://somewhere.org/hwconnect/services/" + method);
    },
    async: false,
    type: "POST",
    url: theURL,
    contentType: "text/xml; charset=\"utf-8\";",
    data: soapRequest,
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert("XMLHttpRequest Failure: " + XMLHttpRequest.statusText);
    }
});

}

A: 

This is probably not a SOAP issue but an issue with how you're posting the data:

400 error explained

I'd examine the final HTTP headers you're sending to verify they are correct (especially the data size)

John Weldon
Going to take a look at the headers.. Thanks
Nick
A: 

I don´t know json but soapaction header should look like this


SOAPAction: "myaction"

so the line:


xhrObj.setRequestHeader("SOAPAction", "http://somewhere.org/hwconnect/services/" + method);

should probably look like this to be correct:


xhrObj.setRequestHeader("SOAPAction", "\"http://somewhere.org/hwconnect/services/" + method + "\"");
Jens Granlund