Find your content:

Search form

You are here

Importing UPS Street Address WSDL into Apex

 
Share

Have anybody been able to successfully use the UPS Street Address Validation WSDL in Apex?

I'm getting the following error message when I use the wsdl2apex: "Unsupported WSDL. Found more than one part for message XAVRequestMessage"

Here is the link to the WSDL File

Any ideas?


Attribution to: Joey Chan

Possible Suggestion/Solution #1

Thanks, Andrew. The changes to WSDL worked for me as well. We are planning to build a wrapper service around this service so that this can be called easily from all the channels.

By any chance, has anyone successfully implemented UPS Address Verification API? can you please share your experiences, any shortcomings, etc. Also any sample APEX code for invoking the service would be really useful.


Attribution to: user2338

Possible Suggestion/Solution #2

Do they offer any other versions of the WSDL? Wsdl2apex sometimes doesn't support certain attributes (documentation)

If they have a more modern version of the WSDL you might want to download and attempt to import that one, or your going to have to cross reference the types avaliable and see if they aren't allowed, for example the XAV element that is giving you an issue might need to be changed to XSD to match the namespace definition.


Attribution to: jordan.baucke

Possible Suggestion/Solution #3

Multi-part messages, seems to be an unsupported feature.

<wsdl:message name="XAVRequestMessage">
    <wsdl:part name="Body" element="xav:XAVRequest"/>
    <wsdl:part name="UPSSecurity" element="upss:UPSSecurity"/>
</wsdl:message>

However you can often work around these issues by editing the WSDL and/or the generated code afterwards (something I've become quite familiar with recently). So long as it does not change the XML used at the time the request or response is handled.

In this case I managed to make a small modification to the WSDL to get it to import successfully!

And more importantly retain what I think is still the desired format, which is to send the UPSSecurity part in the SOAP header. Change the above to this..

<wsdl:message name="XAVRequestMessage">
    <wsdl:part name="Body" element="xav:XAVRequest"/>
</wsdl:message>
<wsdl:message name="XAVRequestMessageHeader">
    <wsdl:part name="UPSSecurity" element="upss:UPSSecurity"/>
</wsdl:message>

Next, notice the following, specifically the value of soap:header message attribute is tns:XAVRequestMessage...

<wsdl:input name="XAVRequest">
    <soap:body parts="Body" use="literal"/>
    <soap:header message="tns:XAVRequestMessage" part="UPSSecurity" use="literal">
       <soap:headerfault message="tns:XAVErrorMessage" part="XAVError" use="literal"/>                   
    </soap:header>
</wsdl:input>

Now change the value of soap:header message attribute to the new message created above , tns:XAVRequestMessageHeader. So it now should now look like this...

<wsdl:input name="XAVRequest">
    <soap:body parts="Body" use="literal"/>
    <soap:header message="tns:XAVRequestMessageHeader" part="UPSSecurity" use="literal">
         <soap:headerfault message="tns:XAVErrorMessage" part="XAVError" use="literal"/>
    </soap:header>
</wsdl:input>

Note: The key thing I've done is create a new message for the part in question and referenced that message in the soap:header element.

Sure enough looking at the generated code, I can see the SOAP header element where it should be. So you should be good to go and try calling it now!

    public wwwUpsComXmlschemaXoltwsUpssV10.UPSSecurity_element UPSSecurity;
    private String UPSSecurity_hns = 'UPSSecurity=http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0';

If your happy to use the version of the WSDL referenced in this answer, here is a copy of it modified as per the instructions above.


Attribution to: Andrew Fawcett

Possible Suggestion/Solution #4

Just looking at the WSDL, and the XAVReqeuestMessage message is comprised of two elements :

<wsdl:message name="XAVRequestMessage">
<wsdl:part name="Body" element="xav:XAVRequest"/>
<wsdl:part name="UPSSecurity" element="upss:UPSSecurity"/>
</wsdl:message>

I'm wondering if Apex is having a problem with this, one idea would be try commenting out the UPSSecurity (which is referenced as a soap header) and move the definition upto the complex type definitions.

Commenting it out and reducing it to one part should let you generate the apex.


Attribution to: techtrekker

Possible Suggestion/Solution #5

USPS seems to offer REST API support too : http://blog.programmableweb.com/2007/11/08/5-apis-to-track-your-packages/

Check the above blog, I tried playing around and ended up in this page. https://www.usps.com/business/webtools.htm

Not sure how helpful this will be but REST API is wasy easier than parsing XML through WSDL

Hope this helps


Attribution to: Rao
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4000

My Block Status

My Block Content