You need to sign in to do that
Don't have an account?
Simba
Error while reading the response from webService
Is there a way to make a call to the external webService from Apex and then do the parsing of the response manually, rather than using WSDL2Apex.
I am not able to import the WSDL into Apex, since the response has anyType keyword in it. I changed the keyword to anyType_x, and was able to import the WSDL. However, since the webService returns anyType as an element in its response, it fails when it's about the parse the response. (anyType not found, since I changed this to anyType_x).
I appreciate any advice on this.
Thanks
Hey, SOAP message is just a HTTP POST request. You just put the entire SOAP message from <SOAPEnvelope> to </SOAPEnvelope> in the HTTP body.
To prove that, generate SOAP Message and test the web service call with other tools like soapUI. Then, copy & paste the entire XML of the envelop part into 1 string and put that into the Http Request body, and make a POST call. See what's returned from web service in the HttpResponse.
And, you generate the same XML with the XMLDom class or XmlStreemWriter class. That's it.
I feel you know how to do it with this.
THomasTT
All Answers
Yes. I used to be on the same path. In my case, WSDL2Apex accepts only wrapped input/output but my WSDL (from a product) wasn't.
You can use Http/HttpRequest/HttpResponse to make a Http Request call by your self. It's on the manual and it has a good sample code.
Another thing you should know is a XML parser. SFDC provides XmlStreamReader, which is a kind of SAX parser, is not very easy to use. There is a very very useful Code Share posted by Ron Hess.
http://developer.force.com/codeshare/apex/ProjectPage?id=a0630000002ahp5AAA
By using these, you can construct your SOAP Request message and parse SOAP Response message by yourself. I hope your WSDL is not so huge. You can even call RESTful web service from SFDC.
However, I wish SFDC's WSDL2Apex could be smarter...
ThomasTT
Thanks for the response. I understand that I can make a HTTP, POST and GET calls using HTTP send API. However, how do I make a SOAP call with the help of HTTP send.
I am not sure, where do I set the parameters that is required for the soap envelope in the req object. I don't think I can simply pass the whole request string to the HTTP.send API.
Would be able to give me an algorithm or a samle code to make SOAP calls using HTTP.send.
Thanks
Hey, SOAP message is just a HTTP POST request. You just put the entire SOAP message from <SOAPEnvelope> to </SOAPEnvelope> in the HTTP body.
To prove that, generate SOAP Message and test the web service call with other tools like soapUI. Then, copy & paste the entire XML of the envelop part into 1 string and put that into the Http Request body, and make a POST call. See what's returned from web service in the HttpResponse.
And, you generate the same XML with the XMLDom class or XmlStreemWriter class. That's it.
I feel you know how to do it with this.
THomasTT
Thanks for the repy. I just tried it, It kind of works but now I get a SOAP Fault Message -
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unable to handle request without a valid action parameter. Please supply a valid soap action.</faultstring>
<detail />
</soap:Fault>
Following is the code snippet
------
String endpointurl = 'http://............................';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointurl);
req.setMethod('POST');
String sreq = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inf="....."><soapenv:Header /><soapenv:Body>......</soapenv:Body></soapenv:Envelope>';
req.setBody(sreq);
HttpResponse res = h.send(req);
return res.getBody();
-----------
Thanks again for the quick responses
ok, so you tried the SOAP message with soapUI or something? and it was successed, right?
so, look at the entire HTTP message not just SOAP Message. There must be an HTTP Header line called "SOAPAction". You need to add this header line by using HttpRequest.setHeader(String key, String value). SOAPAction is supposed to be in the WSDL.
Good luck!
ThomasTT
Great! Thanks a lot for your expertise.
I did find soapAction in the WSDL, which I added as part of the request header -
req.setHeader('soapAction','serviceName/operation');
In addition I also had to specify the content type as text/xml -
req.setHeader('Content-Type','text/xml');
Thanks for your help
Oh, you almost found the way by yourself! Good!
ThomasTT