Thursday, February 23, 2012

Salesforce.com - Common issues while creating APEX from WSDL file

I faced lots of issues while creating APEX classes Generated by wsdl2apex tool of Salesforce. I really want to take note on some nasty ones which keep our days/night busy.

If you ever had chance to work this yourself you must know that Salesforce does not support WSDL with <Import> tags; it means if your client or fellow external application team member provides you a WSDL which have couple of these tags then Salesforce will straightaway reject these saying <import> is not supported. Only solution to work this is manually copying the referenced schema to the parent wsdl file.

Let say you WSDL file looks something like this..this is an example of Referenced Schema

 <wsdl:types>
   <xsd:schema targetNamespace="test.namespace">
      <xsd:import schemaLocation="testlocation" namespace="test.namespace"/>
    </xsd:schema>

 </wsdl:types>

Here above highlighted import tags are not supported. The solution for the above issue is simple ; just copy paste the content of schema from location "testlocation" inside <wsdl:types>, thats it. Some times there are dozens of import statements in WSDL and it becomes deficult to manually do so and these manual changes are error prone. So I will recommend to search for some WSDL flatner tool for this. I have used this one couple of times  http://wsdlflattener.codeplex.com .

Also if your WSDL  contains reference to another WSDL like the one highlighted below; this is an example of Referenced WSDL


<wsdl:definitions name="testservice" targetNamespace="testns" >
    <wsdl:import namespace="testwsdl" location="testlocation"/>

       <wsdl:types>.........
         ........
         .......
       </wsdl:types>
         ...................
         ...................
</wsdl:definitions>


This situation requires pure manual intervention as this is not supported by any flattner tool as of now.In fact the correct statement would be I am not able to find such tool myself till now.Now the steps needed to resolve this are -

  • Use  http://wsdlflattener.codeplex.com tool and create the flattened file.This will copy the Schemas from referenced WSDL location and auto merge some of the <WSDL:definition> tags.
  • Go to the referenced WSDL file ; copy the following tags from the referenced location to the parent WSDL - <wsdl:message> and <wsdl:portType>
  • Copy the targetnamespace="xyzee" from referenced WSDL location to <WSDL:definition> of Parent.
  • You need to check if any other namespace is required to be copied from referenced WSDL to  Parent WSDL:definition; you can do this my comparing the namespaces used.


Hope these steps will resolve some of your issues if you comes up with problems.








2 comments:

  1. Hi Amit,

    Thanks for providing the pointers.

    I am having the same problem in generating code from WSDL, the WSDL contains an import tag, I tried to replace import tag with the contents of other WSDL file.

    The WSDL is parsed with no errors, but while code generation it is giving errors like: "Message not found" or "Schema not found".

    In the parent WSDL targetNameSpace is having an absolute URL and the referenced WSDL has relative URL specified in the TargetNameSpace.

    Can you please provide some help on how to merge the WSDLs?

    Thanks,
    Neeraj

    ReplyDelete
  2. Hi Amit,
    Thanks for provide this way.But this way is very complex and tricky.Mostly we can't any success on same.

    ReplyDelete