Page 1 of 1

How can I view a SOAP response?

Posted: Fri Aug 08, 2014 8:20 pm
by gabrielp
Hey guys,

I'm stuck on this problem. I think I'm getting a SOAP exception as a response but I can't view it. I tried logging the response but it just shows "[object Network8::SOAP_ex]". Does anyone know how I could examine this response?



I tried taking the response and using writeToFile() but that function just returns a boolean on success and I don't know how to see the contents of that file. I also tried parseBody() but I don't know what the documentation means by the "element name".



Anyone have any idea how I can see what's in that response?





var wsdl = 'http://192.168.1.XX/EnterpriseWebServic ... .asmx?wsdl';



try{



var soap = new SOAP();

var xml = '<?xml version="1.0" encoding="utf-8"?>' +

'<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/">' +

'<soap:Body>' +

'<GetDetailJobStatus xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">' +

'<Credentials>' +

'<Username>myusername</Username>' +

'<Password>mypass</Password>' +

'</Credentials>' +

'<JobNumber>123456</JobNumber>' +

'</GetDetailJobStatus>' +

'</soap:Body>' +

'</soap:Envelope>';

soap.setBody(xml);



var response = soap.requestMessage(wsdl, 'http://localhost/EnterpriseWebService/E ... lJobStatus');



s.log(2, "Result is...");

s.log(2, response);



soap.writeToFile('request.xml');

response.writeToFile('response.xml');



} catch ( exception ) {



s.log(3, exception );

}


How can I view a SOAP response?

Posted: Fri Aug 08, 2014 9:22 pm
by gabrielp
Okay, answered my own question. These lines allowed me to overwrite the input file with the resulting response:



// Overwrite the input file with the response

response.writeToFile( job.getPath() );

job.sendToSingle( job.getPath() );



Now the issue I'm having is parsing the response. This is my response:



<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

<GetDetailJobStatusResponse xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">

<GetDetailJobStatusResult>1000 Digital Prepress</GetDetailJobStatusResult>

</GetDetailJobStatusResponse>

</soap:Body>

</soap:Envelope>



So how would I get that value of GetDetailJobStatusResult as a string?



I was hoping something like this would work, but it doesn't:



s.log(2, response.parseBody('GetDetailJobStatusResponse'));

How can I view a SOAP response?

Posted: Mon Aug 11, 2014 4:06 pm
by dkelly








1000 Digital Prepress










Try something like:



s.log(-1, "Result: %1", result[http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse][GetDetailJobStatusResult]);


How can I view a SOAP response?

Posted: Mon Aug 11, 2014 4:32 pm
by gabrielp
dkelly wrote: Try something like:



s.log(-1, "Result: %1", result[http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse][GetDetailJobStatusResult]);




Getting this:

Error: Trying to access undefined member 'http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse'



Which is a similar error to anything I try when guessing at the structure of that object. I really wish there was the equivalent of var_dump() or print_r() for cases like these. Luckily, I think I might actually just output an entire XML file so I can continue with this project, so I think I can avoid parsing the XML within the script. If anyone figures out how to parse through the response, I would be interested though!

How can I view a SOAP response?

Posted: Mon Aug 11, 2014 4:58 pm
by dkelly
Here's a routine I wrote to dump any JS object.



function mydump(arr,level) {

var dumped_text = "";

if(!level) level = 0;



var level_padding = "";

for(var j=0;j<level+1;j++) level_padding += " ";



if(typeof(arr) == 'object') {

for(var item in arr) {

var value = arr[item];



if(typeof(value) == 'object') {

dumped_text += level_padding + "'" + item + "' ...n";

dumped_text += mydump(value,level+1);

} else {

dumped_text += level_padding + "'" + item + "' => "" + value + ""n";

}

}

} else {

dumped_text = "===>"+arr+"<===("+typeof(arr)+")";

}

return dumped_text;

}





Dwight Kelly

How can I view a SOAP response?

Posted: Tue Aug 12, 2014 3:02 pm
by gabrielp
dkelly wrote: Here's a routine I wrote to dump any JS object.


Awesome Dwight. That will come in handy.



Jonas from Enfocus was able to answer my question. Here it is for anyone who might encounter this in the future:



s.log(2, response.parseBody("//GetDetailJobStatusResponse/GetDetailJobStatusResult"));


How can I view a SOAP response?

Posted: Mon Aug 18, 2014 4:26 pm
by gabrielp
One more update. It appears that the code above did not actually work. This is because EPMS Connect returns nodes with a null namespace when the default namespace of "soap" is set on the response. This means, you have to specify a null namespace when trying to grab values out in your xpath.



This code uses a more specific xpath and does work.

var responseMessage = response.parseBody("/soap:Envelope/soap:Body/*[name()='SubmitOrderResponse']/*[name()='SubmitOrderResult']/*[name()='Message']");

s.log(-1, responseMessage);



Dominick Peluso, peluso.dominick@gmail.com

Re: How can I view a SOAP response?

Posted: Fri Apr 29, 2016 1:34 pm
by Scheer
An old topic, but very helpful! Thanks Dominick!