10

I wrote a simple JAX-WS web service for tomcat application server on java.

I have one interface and on implementation class:
interface

@WebService(name = "myWs")
@SOAPBinding(style = Style.RPC)
public interface IMyWs {
    @WebMethod(operationName = "getUser")
    Response getUser(@WebParam(name = "phone", mode = Mode.IN) String phone);

}


implementation

@WebService(endpointInterface = "ge.mari.IMyWs")
public class MyWs implements IMyWs {
    @Override
    public Response getUser(String phone) {
               // SOME CODE
        return response;
    }
}

My problem is that, in my wsdl file Response class is defined in xsd file.
This is the snippet from my wsdl file

<types>
<xsd:schema>
          <xsd:import namespace="http://ws.mari.ge/" schemaLocation="http://localhost:8080/MyServcie/MyWs?xsd=1">
</xsd:import>
</xsd:schema>
</types>

How can I make web service to generate all types in WSDL file instead of separate XSD file?
Should I change any configuration or add some annotation to my web service?

3 Answers 3

12

You can have JAX-WS insert the generated schema into your WSDL file by using the

-inlineSchemas

command line switch. [1]

If you're using Maven in your project you can configure the JAX-WS maven plugin to do the same with the inlineSchemas configuration element in your execution configuration as follows: [2]

<plugin>
  <groupId>org.jvnet.jax-ws-commons</groupId>
  <artifactId>jaxws-maven-plugin</artifactId>
  <version>2.2</version>
  <executions>
    <execution>
      <id>SomeId</id>
      <goals>
        <goal>wsgen</goal>
      </goals>
      <phase>prepare-package</phase>
      <configuration>
        <sei>some.class.Name</sei>
        <genWsdl>true</genWsdl>
        <keep>true</keep>
        <resourceDestDir>some/target/dir</resourceDestDir>
        <inlineSchemas>true</inlineSchemas>
      </configuration>
    </execution>
  </executions>
</plugin>

No changes to your Java class are necessary.

[1] http://jax-ws.java.net/nonav/2.2.1/docs/wsgen.html

[2] http://jax-ws-commons.java.net/jaxws-maven-plugin/wsgen-mojo.html

0
0

AFAIK it ist not possible to have JAX generate a WSDL with schemas inline.

BTW: Separating the WSDL definition and the XSD schema is a good move (you might want to use the object structure defined by the schema in a different context e.g. storing data to files or something like that).

That said: If you need an "all in one" WSDL (because some ancient client requires it) you can always have jax-ws generate the WSDL initially and then edit it to your heart's content. The edited WSDL can be included using the wsdlLocation parameter of the @WebService annotation.

2
  • It indeed is possible to instruct JAX-WS to inline the schema. See my answer above for how instructions on how to achieve that.
    – Kallja
    Aug 6, 2013 at 12:04
  • @Kallja: I assumed the OP was referring to the WSDL generated by the application server (because there is a schemaLocation="http://localhost:8080/MyServcie/MyWs?xsd=1" in the WSDL-fragment. I don't know of a way to convince an app server to generate an all-in-one WSDL... BUT your point is a good one. I need to remember the wsgen param you used. :-)
    – secra
    Aug 6, 2013 at 14:49
0

It is actually not possible to use inlineSchemas with the runtime WSDL generator. I debugged the WSDL generation and found this line in the EndpointFactory, where the inlineSchemas feature (which actually is present in the wsgen tool) is just set to false:

    /**
     * Generates the WSDL and XML Schema for the endpoint if necessary
     * It generates WSDL only for SOAP1.1, and for XSOAP1.2 bindings
     */
    private static SDDocumentImpl generateWSDL(WSBinding binding, AbstractSEIModelImpl seiModel, Collection<SDDocumentImpl> docs,
                                               Container container, Class implType) {
        // [...]
        WSDLGenInfo wsdlGenInfo = new WSDLGenInfo(); 
        // [...]
        wsdlGenInfo.setInlineSchemas(false);
        // [...]
        seiModel.getDatabinding().generateWSDL(wsdlGenInfo);
        // [...]
    }

https://github.com/eclipse-ee4j/metro-jax-ws/blob/f37dae6bdfd03bafdad63ed05b27dbfc3c38af1b/jaxws-ri/rt/src/main/java/com/sun/xml/ws/server/EndpointFactory.java#L658

There is also an open issue for JAX-WS to change this (but I guess there is not much hope for changes in JAX-WS anymore). https://github.com/eclipse-ee4j/metro-jax-ws/issues/49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.