Skip to main content

How to set namespace prefix for JAX-WS generated WSDL file?

5 replies [Last post]
jenajena
Offline
Joined: 2012-07-11
Points: 0

Hello,

I have developped a small web service in contract first mode. So I have created my class with @WebService annotation.
My webservice has one operation which takes a "Credentials" bean as input. It is defined in the same Java package. On my bean I use @XmlRootElement and @XmlElement to specify the namespace, such as namespace="http://toto.fr".
In the WSDL, I would like to be able to explicitly specify the prefix for this namespace but I am unable to do that.
I tried by adding a package-info.java file with:

@XmlSchema(namespace = "http://toto.fr", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
@XmlNs(prefix = "t", namespaceURI = "http://toto.fr")})

But nothing is changed in the WSDL.

Does anyone know how to do that ?
Thanks a lot.

Jena

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Redema
Offline
Joined: 2012-07-16
Points: 0

Hi Jena,

in the @WebService annotation you can specify the wsdl namespace by adding the attribute "targetNamespace=" like in

@WebService(serviceName = "TestService", targetNamespace="http://my.test.ns")

Hope this helps.

Regards,

Martin.

jenajena
Offline
Joined: 2012-07-11
Points: 0

Hi Redema,

Thank you for your answer.
But my point is not to set the namespace but to set the prefix namespace.

Regards,

JB

Redema
Offline
Joined: 2012-07-16
Points: 0

Hi Jena,

sorry i have misread your post.

I did some search and tests myself but can not get it working as well.

Strange: this is the way it should be.

On the other hand: why you want a specific prefix where the default/generated is perfectly fine. Its valid xml. The client will always understand the default/generated prefix.

Martin.

jenajena
Offline
Joined: 2012-07-11
Points: 0

I fully agree that specifying a prefix is not really usefull as the default/generated one is perfectly fine.
But my final customer is complaining of the namespaces because he is using SoapUI to create some SOAP requests and with the default namespace it is cosmeticly not really readable.

Jena

Redema
Offline
Joined: 2012-07-16
Points: 0

Hi Jena,

looks like you only need the specify the "better readable" namespace. No need for the prefix.

Maybe the package-info.java is ignored because we use the @WebService() annotation.

Sorry I can not be more helpful.

Martin.