Is there an good way to (automatically) create proper request bodies from WSDL files just as a plain xml string? I need this for perfoming calls from APEX to different salesforce APIs, mostly for the Partner SOAP API. Here is an example which I figured out (just to demonstrate what I mean):
public static String login(String username, String passwordAndToken) {
Http h = new Http();
HttpRequest req = new HttpRequest();
URL baseUrl = URL.getSalesforceBaseUrl();
req.setEndpoint( baseUrl.toExternalForm() + '/services/Soap/u/'+'30.0');
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', '""');
string body = ''
+'<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">'
+'<se:Header xmlns:sfns="urn:partner.soap.sforce.com">'
+'<sfns:SessionHeader>'
+'<sessionId>'+'</sessionId>'
+'</sfns:SessionHeader>'
+'</se:Header>'
+'<se:Body>'
+'<login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com">'
+'<username>'+username+'</username>'
+'<password>'+passwordAndToken+'</password>'
+'</login>'
+'</se:Body>'
+'</se:Envelope>'
;
req.setBody(body);
HttpResponse res = h.send(req);
return res.getBody();
}
My question is all about the body. So as you see, I'm generating the body string for the API call for the function login defined in the partner.wsdl.
Now the partner.wsdl is full of other functions which I want to call. Composing the body strings manually is kind of time wasting and error prone.
Is there a good way (or tool) to generate and capture those strings?
I know there are also build in mechanisms to create APEX classes with Wsdl2Apex but for many reasons I would prefer it the text-way because there are a lot of complex types in the salesforce APIs and Wsdl2Apex is simply not doing the best job. I just don't want to do it all manually by hand.


