Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 10 down vote accepted

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.

share|improve this answer
    
Thanks for the very detailed answer Andrew! I got a bit confused on thse second part. You mentioned change this "<wsdl:input name="XAVRequest">...</wsdl:input>" but while checking it already has that value. Would you be able to share your copy of the wsdl that you were able to successfully import? Thanks! –  Joey Chan Nov 5 '12 at 8:19
2  
No problem, I've updated the answer so it is hopefully clearer for you and future readers. While I have also shared the WSDL here, gist.github.com/4016172. Enjoy! –  Andrew Fawcett Nov 5 '12 at 9:07

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.

share|improve this answer
    
Yep that's it, though the key thing is to ensure that the UPSSecurity element is still sent in the header. See my answer below. Looking at the generated code it appears to have still achieved the goal of the orignal WSDL. –  Andrew Fawcett Nov 2 '12 at 17:15

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
3  
Welcome to the Salesforce Stack Exchange (SFSE)! Your posting is not an answer to the question. If you have a specific question please feel free to ask your own question. The SFSE format is a little different than other types of message boards. There is more information about SFSE in the about and faq. –  Peter Knolle Feb 1 '13 at 23:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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