Friday, August 21, 2009

JAX-WS "Two classes have the same XML type name"

When generating the Java classes using wsgen from a WSDL I was getting the following error:

Two classes have the same XML type name "{http://myservice/}foo". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:

As suggested by the exception I tried changing @XmlType but that was fine for me.
This link offers the same solution and it also suggests to change Response classes which I think its an extreme solution.

Anyway in my case the problem was that I generated the classes and I wanted to change the package name.
Everything worked fine, compiled and the webservice deployed successfully.
When viewing the WSDL I got the above error.
In my case the solution was just to update the new namespace in the Webmethod attribute.

@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "foo", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.foo")
@ResponseWrapper(localName = "fooResponse", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.FooResponse")

The attribute className had to be updated :(

3 comments:

  1. Very good! Thank you! Brazil.

    ReplyDelete
  2. Ahh, thank you. After hours of trying to debug your post pointed me back to the (obvious) problem that I had moved the generated .java files into a sub-folder and therefore needed to change the className attribute!

    Thank you!

    ReplyDelete
  3. i have the same problem in my case, you changed className in @RequestWrapper or @ResponseWrapper ?
    object factory must be changed ?

    ReplyDelete