function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SolipSolip 

SOAP callout using HttpRequest- Issues with External schemas in WSDL

Hi,

 

I'm trying to import a service WSDL that uses external schemas. I tried flatenning the WSDL but it uses 5 different xsds all with their own namespaces and all of them are qualified. I can try and change the name spaces but I think the service will not be able to recongnize it as the elements will not have any namespace qualifiers. Including xlms:"service url" might work but I'm not sure how to iclude a namespace in apex for a request generated by wsdl2apex.

 

Another option I'm trying to explore would make use of XML DOM class and HttpRequest/Response classes to manually build the SOAP enveloper and handle responses. Has any one had experiences using Http classes for SOAP callouts?  What would the req.setMethod be?

 

Any help would be appreciated.

 

Thank you

Best Answer chosen by Admin (Salesforce Developers) 
SaraagSaraag
String s='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ><soapenv:Header>headers here,refer WSDL</soapenv:Header><soapenv:Body> request body.Refer WSDL</soapenv:Body></soapenv:Envelope>';
HttpRequest req = new HttpRequest();
req.setEndpoint('the URL from service provider');
req.setMethod('POST');
req.setBody(s);
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', '""');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('Saraag-Here is your response:'+res.getBody());

 The important things here are setMethod to POST, SOAP Action header to "", content type to text/xml. Don't forget to add certs to req headers when doing SSL.

 

Thanks,

Saraag

All Answers

SaraagSaraag
String s='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ><soapenv:Header>headers here,refer WSDL</soapenv:Header><soapenv:Body> request body.Refer WSDL</soapenv:Body></soapenv:Envelope>';
HttpRequest req = new HttpRequest();
req.setEndpoint('the URL from service provider');
req.setMethod('POST');
req.setBody(s);
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', '""');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('Saraag-Here is your response:'+res.getBody());

 The important things here are setMethod to POST, SOAP Action header to "", content type to text/xml. Don't forget to add certs to req headers when doing SSL.

 

Thanks,

Saraag

This was selected as the best answer
Mallik Vemugunta 5Mallik Vemugunta 5
Sarang,

  Can you please example of String s that had Header and body details and how to populate the values in XML using apex.

Regards,
Mallikarjuna