JAX-WS has XSD schema in different URL
Asked Answered
C

2

6

I made a small web service using JAX-WS. The WSDL file has TYPES element like this.

<types>
  <xsd:schema>
  <xsd:import namespace="http://ws.poc.mawia/" schemaLocation="http://localhost:777/ws/hello?xsd=1"/>
  </xsd:schema>
</types>

The URL for web service is http://localhost:777/ws/hello?wsdl and XSD is http://localhost:777/ws/hello?xsd=1 . The XSD Schema file in different location has the data type definitions like this.

...
 ...
    <xs:complexType name="student">
     <xs:sequence>
     <xs:element name="name" type="xs:string" minOccurs="0"/>
     <xs:element name="rollNo" type="xs:int"/>
     </xs:sequence>
    </xs:complexType>
  ...
 ...

Most of the WSDL files I have seen usually has the complete XSD definitions inside the WSDL file itself but JAX-WS is placing it in a different location.

Is this how it should be? How can I configure JAX-WS to place all XSD definitions in one WSDL file?

Currency answered 16/4, 2013 at 6:52 Comment(0)
S
9

Is this how it should be?

Separating the XSD from the WSDL is the default behaviour in JAX-WS, and you shouldn't need to worry too much about it. Up-to-date WS frameworks (including WCF) are generally able to handle that. Depending on the size of the XSD, importing it might make the WSDL more readable for a human. For a small web service it would certainly be easier to have an embedded schema, but it's also not too much of a problem to import it.

How can I configure JAX-WS to place all XSD definitions in one WSDL file?

I don't know of a direct way to make the runtime embed the schema in the WSDL, but there is a workaround through which you can achieve this:

  1. Publish your endpoint and save the WSDL and the XSD
  2. Manually copy the content of the XSD into the types section of the WSDL and replace the schema import there
  3. Save the merged WSDL file somewhere where your application can access it as a resource
  4. Have your web service load the merged WSDL. This will stop the dynamic generation however, you will have to manually update the WSDL each time you make changes to the interface

You can implement 4. by customizing the @WebService annotation. This might look somewhat like this:

@WebService( wsdlLocation = "MyWebService.wsdl")
public class MyWebService { .... }
Staw answered 16/4, 2013 at 8:56 Comment(2)
MyWebService is a class or interface?Currency
In the setting I have here, it is a class. MyWebService still implements an interface (with the @WebService annotation) and points to that interface with the endpointInterface attribute. Aka: @WebService( endpointInterface="some.package.MyPortType", ...)Staw
S
0

There isn't anything wrong with your approach. WSDL pointing to another wsdl using URL is fine.

If you don't want it, mention the wsdl location using wsdlLocation attribute of @WebService annotation. But again with this approach you will have to modify wsdl manually.

Solo answered 16/4, 2013 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.