6

I have a wsdl with an embedded xsd.

<wsdl:definitions name="AcmeService"
    targetNamespace="http://www.acme.com/services/Acme/WcfService"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://www.acme.com/services/Acme/WcfService"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <xsd:schema targetNamespace="http://www.acme.com/services/Acme/WcfService/Imports">
            <xsd:import schemaLocation="http://services01.acme.com/WebServices/AcmeWcfClient/service/AcmeService.svc?xsd=xsd0" namespace="http://www.acme.com/services/Acme/WcfService" />
            <xsd:import schemaLocation="http://services01.acme.com/WebServices/AcmeWcfClient/service/AcmeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
        </xsd:schema>
    </wsdl:types>
    <!-- Some more WSDL Content -->
</wsdl:definitions>

My 'xsd' contains the following definitions:

<xs:schema elementFormDefault="qualified" targetNamespace="http://www.acme.com/services/Acme/WcfService">
    <xs:element name="SetApplication">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="application" nillable="true" type="tns:Application"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="Application">
        <xs:sequence>
            <xs:element minOccurs="0" name="SomeElement" nillable="true" type="xs:string"/>
            <xs:element minOccurs="0" name="AnotherElement" nillable="true" type="xs:string"/>
            <xs:element minOccurs="0" name="AcmeDetails" nillable="true" type="tns:Acme"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="Application" nillable="true" type="tns:Application"/>
    <xs:complexType name="Acme">
        <xs:sequence>
            <xs:element minOccurs="0" name="PropertyOne" nillable="true" type="xs:string"/>
            <xs:element minOccurs="0" name="PropertyTwo" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="Acme" nillable="true" type="tns:Acme"/>
    <xs:element name="GetAcmeDetails">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="acme" nillable="true" type="tns:Acme"/> <!-- "acme" name is lowercase on purpose -->
            </xs:sequence>
       </xs:complexType>
    </xs:element>
    <xs:element name="GetAcmeDetailsResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="GetAcmeDetailsResult" nillable="true" type="tns:Acme"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

My problem comes from the fact that, when generating the service stubs using wsimport, I am left with the following definition for Acme:

@XmlType(name = "Acme", namespace = "http://www.acme.com/services/Acme/WcfService", propOrder = {

The issue being that I need both Acme and AcmeDetails to resolve to the same underlying Acme object.

Looking at a couple of other, similar, questions (here, here, and here) I have tried to create a binding using the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  wsdlLocation="Acme_Service.wsdl">
    <enableWrapperStyle>true</enableWrapperStyle>
    <enableAsyncMapping>false</enableAsyncMapping>
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema/xs:complexType[@name='Application']/xs:sequence/xs:element[@name='AcmeDetails']">
        <jaxb:class name="AcmeDetails"/>
    </jaxws:bindings>
</jaxws:bindings>

The above binding generates the class 'AcmeDetails' but the XMLType Annotation remains 'Acme'.

Any help in generating bindings to both Acme and AcmeDetails in the above extract greatly appreciated.

Community
  • 1
  • 1
radimpe
  • 3,197
  • 2
  • 27
  • 46

1 Answers1

5

External XML schema files imported by the WSDL file can be customized using a JAXB external binding declaration file:

<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="1.0">
    <jxb:bindings schemaLocation="your-imported-xsd-location" node="/xsd:schema">
        <jxb:schemaBindings>
            <jxb:package name="fromjava.client"/>
        </jxb:schemaBindings>
    </jxb:bindings>
...
</jxb:bindings>

The external JAXB binding declaration file can be passed to wsimport using the -b switch. See the JAX-WS tools documentation for details.

The above excerpt comes from this link; while most likely applicable for your version, you could double check the same;

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62
  • Thanks for the info. I did read that article previously (I think you may have highlighted that in a separate post). The bit that I am perhaps missing is that I am probably mixing up my `wsdlLocation`, `node`, and `schemaLocation` in my bindings file. I'm pretty sure my `XPath` is correct though (both documented attempts should have worked) but somewhere in the mix of things I get it wrong. – radimpe Apr 02 '12 at 19:28
  • Actually, these are two separate bindings. If you take a closer look, {http://java.sun.com/xml/ns/jaxb}bindings, which has the schemaLocation attribute for the external XSD file (see the XSD [here](http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd)) is different than {http://java.sun.com/xml/ns/jaxws}bindings, which has the wsdlLocation attribute (see the schema [here](http://java.sun.com/xml/ns/jaxws/wsdl_customizationschema_2_0.xsd)). Again, one if custom binding for XSD, the other one is custom bindings for WSDL. – Petru Gardea Apr 02 '12 at 22:48
  • I've sorted out the schema/wsdllocation part of my bindings.xml. I still have the original problem where, depending on the path through which you access `Acme` it either needs to generate a mapping to `AcmeDetails` or remain simply `Acme`. – radimpe Apr 03 '12 at 10:19