[SalesForce] Salesforce apex Inbound SOAP web service response

My requirement is that I have to create an inbound SOAP web service which will return a list of data based on the input parameters.
I am using wrapper classes to build the output.

global class Account{
        webservice string Id;
        webservice string Name;
        webservice list<SystemWrapper> Systems;
}

global class SystemWrapper{
        webservice string Id;
        webservice string Name;
        webservice string ProductLine;
        webservice string SystemRoleId;
}

Now i have the following questions in the response which is generated

  1. How do i specify the sequence, because the client system wants the elements in the soap reponse xml in a particular sequence. Are the nodes ordered in alphabetical order automatically?

  2. How do i remove the result node which is added automatically to the response
    for ex :

         <result>
               <Account>
                  <Id>001M000000moDXQIA2</Id>
               </Account>
         </result>
    
  3. And each node name should be pre-pended with a namespace that is defined in the soap:Body.

Any help is much appreciated. Thanks!

Hi Daniel
Thanks for your reply.

However i have one more question

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://soap.sforce.com/schemas/class/CustomerPortalIntegrationService">

?

There are namespaces added to the request xml — "cus" but whereas the response xml does not have any namespace.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/CustomerPortalIntegrationService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Can we modify the WSDL such that the response has namespaces.

Best Answer

The order of the xsd:sequence elements for a complexType that you define does appear to be alphabetical. At the very least, you have no other way to control the order of the elements within the sequence.

I don't think you can remove the 'result' element from the generated *Response elements. It's part of the mechanism that if used for handling collection parameters.

There should be no need to prefix the namespace to the nodes when the targetNamespace is defined. That said, as long as the inbound SOAP request matches the WSDL schema it should be fine to specify the namespace on each element.