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?
It is primarily used to define the elements, attributes and data types the document can contain. The information in the XSD is used to verify if each element, attribute or data type in the document matches its description.
if the xsd is part of WSDl and sometime you need to extract the XSD from wsdl, there are no utility to do this task for you. The wsimport tool from jdk 1.7 is used to parse an existing WSDL and generate required files (JAX-WS portable artifacts) for WSDL. Java code to extract and write xsd into separate file.
xsd is the XML schema you will use as input to the JAXB binding compiler, and from which schema-derived JAXB Java classes will be generated.
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:
types
section of the WSDL and replace the schema import thereYou can implement 4. by customizing the @WebService
annotation. This might look somewhat like this:
@WebService( wsdlLocation = "MyWebService.wsdl")
public class MyWebService { .... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With