0

I have seen multiple posts online talking about how to read in XML data from a web request using HttpRequest, but I cannot seem to make it work or find any documentation on it. The closest I have gotten is to making it work is to enclose the xml in

< request >....< /request >

which is not acceptable for my case.

Is there anyway to send a raw string of xml to salesforce for manual parsing and not having to alter or encapsulate that string?

edit.

    < B:Envelope xmlns:B="http://schemas.xmlsoap.org/soap/envelope/" xmlns:A="theircustomuri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       < SOAP:Header xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12">
          < SOAP-SEC:Signature SOAP:mustUnderstand="1">
             < Signature xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:C="theircustomuri" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
                < SignedInfo>
                   < CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                   < SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                   < Reference URI="#Body">
                      < Transforms>
                         < Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                      < /Transforms>
                      < DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                      < DigestValue>xxxxxxxxxxxxxxxxx< /DigestValue>
                   < /Reference>
                < /SignedInfo>
                < SignatureValue>xxxxxxxxxxxxxxxxx< /SignatureValue>
                < KeyInfo>
                   < X509Data>
                      < X509Certificate />
                      < X509IssuerSerial>
                         < X509IssuerName>Oxxxxxxxxxxxxxxxxxxx< /X509IssuerName>
                         < X509SerialNumber>xxxxxxxxxxxxxxxxx< /X509SerialNumber>
                      < /X509IssuerSerial>
                   < /X509Data>
                < /KeyInfo>
             < /Signature>
          < /SOAP-SEC:Signature>
       < /SOAP:Header>
       < B:Body id="Body">
          < B:Fault>
             < B:faultcode>Client.invalidData< /B:faultcode>
             < B:faultstring>invalidData< /B:faultstring>
             < B:detail>
                < faultdetails>detailed info< /faultdetails>
             < /B:detail>
          < /B:Fault>
          < A:AdditionalInfo version="2.0">
             < A:SenderID>FS000< /A:SenderID>
             < A:TargetID>F000BK< /A:TargetID>
          < /A:AdditionalInfo>
       < /B:Body>
    < /B:Envelope>
  • 1
    Are you making a call out from Salesforce, or is someone else making a call in to Salesforce? Is the service REST or SOAP-based (you've tagged both)? Can you give a concrete example of the issue you're confronting? – David Reed Jan 26 at 17:38
  • We'd have to see a sample of what you're trying to parse to know exactly what's wrong. – sfdcfox Jan 26 at 17:51
  • Yes, this is a callout into Salesforce that should be SOAP, but it doesn't meet Salesforce's standards for a soap message. One of the things would be having a custom namespace on the body data instead of the "soap.sforce.com/schemas/class....." So I keep reading about people using custom rest services in salesforce to create a listener to manually parse the data, but i have been stuck for months. – awh01 Jan 26 at 17:53
  • I have added the xml to the post. Thank you – awh01 Jan 26 at 17:56
  • 1
    @awh01 Are those tags literally < B:Body> with the leading whitespace? That wouldn't be valid XML. When I fix the whitespace issue, the XML parses just fine. – sfdcfox Jan 26 at 18:32
0

The answer to this is as @sfdcfox suggested. You can just create a rest endpoint without parameters (so salesforce doesn't try to automatically deserialize).

 @HttpPost
global static String doPost() {
    String soapRequestBody = RestContext.request.requestBody.toString();
    RestResponse res = RestContext.response;
    res.statusCode = 200;
    res.responseBody = Blob.valueOf('OK');
    return 'OK';
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.