2

I am trying to integrate with a web service which utilises two namespaces, and has elements which need to reference the other namespace. For example:

<xsd:schema targetNamespace="http://namespace1.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:complexType name="GetLocationLocationType">
        <xsd:sequence>
            <xsd:element ref="oa:Address"/>
        </xsd:sequence>
    </xsd:complexType>
<xsd:/schema>

<xsd:schema targetNamespace="http://namespace2.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:element name="Address" type="oa:LocationAddressLineType"/>
<xsd:/schema>

This compiles correctly into Apex code as below:

public class GetLocationLocationType 
{
    public bg_WSAddressOpenAppResources.LocationAddressLineType Address;
    private String[] Address_type_info = new String[]{'Address','http://www.namespace2.com',null,'1','1','false'};
    private String[] apex_schema_type_info = new String[]{'http://www.namespace1.com','true','false'};
    private String[] field_order_type_info = new String[]{'Address'};
}


public class LocationAddressLineType 
{
    public String AddressLine;
    public String CountryCode;
    public String PostalCode;
    public bg_WSAddressOpenAppResources.StatusType Status;
    private String[] AddressLine_type_info = new String[]{'AddressLine','http://www.namespace2.com',null,'0','1','false'};
    private String[] CountryCode_type_info = new String[]{'CountryCode','http://www.namespace2.com',null,'0','1','false'};
    private String[] PostalCode_type_info = new String[]{'PostalCode','http://www.namespace2.com',null,'0','1','false'};
    private String[] Status_type_info = new String[]{'Status','http://www.namespace2.com',null,'0','1','false'};
    private String[] apex_schema_type_info = new String[]{'http://www.namespace2.com','true','false'};
    private String[] field_order_type_info = new String[]{'AddressLine', 'CountryCode','PostalCode','Status'};
}

The issue I'm having is that when the SOAP message is received by the web service, any elements which were used in namespace1 but stored in namespace2 (such as the GetLocationLocationType -> LocationAddressLineType relationship) were incorrectly sent as a namespace1 element (and thus treated as null by the web service).

Therefore my question (eventually!) is whether there is a way to get around the restriction for using 'ref' tags in a WSDL which reference a different namespace? The documentation relating to this restriction can be found here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex.htm

xsd:element. In Apex code saved using API version 15.0 and later, the ref attribute is also supported with the following restrictions:

You cannot call a ref in a different namespace.

Hopefully I've provided enough information, if anything else is needed please let me know. Any advice would be appreciated.

2

I've studied the output code from the WSDL2Apex tool quite a lot for various reasons like this, for example it ignoring xsd:extension. Some can be worked around by modifying the generated code, thus its really a restriction in code generator and not the XML binding annotation you've shown in your question. In this case however, i see that it did correctly generate the annotation with the correct namespace, so in this case there is no such option to modify the code.

I'm sorry but this looks like a real restriction.

  • Thanks for your reply Andrew, I had a feeling this might be the case. – G.W. Dec 18 '13 at 11:20
  • Yeah no problem, i has made be wonder if we have can capture the output from the XML Apex Binding, to amend it via the XML parser in XML before transmitting. Something for a rainy day to look at... – Andrew Fawcett Dec 18 '13 at 14:15
0

WSDL to Apex doesn't support referencing elements from a different namespace:

Apex also supports the following schema constructs:

  • xsd:all, in Apex code saved using API version 15.0 and later
  • xsd:annotation, in Apex code saved using API version 15.0 and later
  • xsd:attribute, in Apex code saved using API version 15.0 and later
  • xsd:choice, in Apex code saved using API version 15.0 and later
  • xsd:element. In Apex code saved using API version 15.0 and later, the ref attribute is also supported with the following restrictions:
    • You cannot call a ref in a different namespace.

Document about the wsdl 2 apex: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex.htm

So if you cannot change the element's namespace, the other alternative is to rely on a regular HTTP callout (as opposed to an Apex web service callout)

Info/links about HTTP callouts:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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