2

I have a couple of SOAP services (implemented in .Net) that I want to generate a Java stub for. The first service was no problem but the second service threw up the error

WSDLToJava Error: 
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8 [0,0]: Two declarations cause a collision in the ObjectFactory class.
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11 [0,0]: (Related to above error) This is the other declaration.

Not being too familiar with this stuff I eventually figured out that two imports in the wsdl are stepping on each other toes

<wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
        ...
        <xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums"/>
        ...
        <xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.ServiceManagement"/>
        ...

The xsd for the first import is of the form

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums" 
           elementFormDefault="qualified"
           targetNamespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums">
    <xs:simpleType name="DeviceIdiom">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Auto"/>
            <xs:enumeration value="Phone"/>
            <xs:enumeration value="Tablet"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="DeviceIdiom" nillable="true" type="tns:DeviceIdiom"/>
    <xs:simpleType name="ServiceManagementSORType">
    ...

More reading and I figured out I had to do something like this

How to resolve collision in the ObjectFactory on wsdl2java?

So my approach has been to try and put a suffix on the end of every simple type (they are all simple types).

So my current command line is

./wsdl2java.bat -impl -server -verbose -autoNameResolution -b bindings.xml ServiceManagement.wsdl

And my binding file is

<jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:version="2.1"> 

    <jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
         <jaxb:bindings node="//xs:simpleType">
            <jaxb:nameXmlTransform>
                <jaxb:typeName suffix="Enums" />
            </jaxb:nameXmlTransform>
        </jaxb:bindings>
    </jaxb:bindings>        
</jaxb:bindings>

But now I am stuck on this error

XPath evaluation of "//xs:schema" results in empty target node

I can not figure out how to get past this error. I am starting to think it has something to do with the fact it's a .Net service and I have to reference the xsd like so

http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8

Any help greatly appreciated.

Community
  • 1
  • 1
YanisTheYak
  • 373
  • 5
  • 14

1 Answers1

0

Finally figured it out, I replaced

<jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">

with

<jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">

Not easy to see is it, but note the capital L in schemaLocation - ouch!

Entire problem eventually fixed by mapping the schema for 'Company.Platform.Datatypes.Enums' to a different package with the binding file

<jaxb:bindings    
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1"> 

<jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8">
    <jaxb:schemaBindings>
      <jaxb:package name="org.tempuri.enums"/>
    </jaxb:schemaBindings>      
</jaxb:bindings>        

YanisTheYak
  • 373
  • 5
  • 14