views:

45

answers:

1

I've been playing around with web services using jbossws-cxf. I don't think the issue is with the implementation I'm using but instead how the code is generated. Here is my pojo with the annotations for a web service.

package com.matt.test.ws;

import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class JbossWSTestImpl {
    private String[] statuses = {"Hello","JbossWS is cool","GoodBye","l33t hax0rz"};
    @WebMethod
    @WebResult(name="status")
    public String getStatus(){
        return statuses[new java.util.Random().nextInt(3)];
    }

}

My soap response when i test the webservice (with soapUI) is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soap:Body>
  <ns2:getStatusResponse xmlns:ns2="http://ws.test.matt.com/"&gt;
     <status>Hello</status>
  </ns2:getStatusResponse>
  </soap:Body>
</soap:Envelope>

Is there a way short of manually editing the wsdl file to modify the namespace that "ns2" is so that I can wrap the response in different tags. What I want is something like

<soap:Envelope ...>
   <soap:Body>
      <MyWSResponse xmlns="http://ws.test.matt.com/"&gt;
         <status>Hello</status>
      </MyWSResponse>
   <soap:Body>
<soap:Envelope>

Are there annotations that I'm not using that can modify that? I haven't found a way to modify the wsdl that way with them as of yet.

UPDATE: changing @WebService to @WebService(targetNamespace="http://MyWSResponse") changed the soap request to the correct tag but the soap response message still uses ns2 instead of MyWSResponse.

+1  A: 

You must add a new attribute to the WebService annotation as:

@WebService(targetNamespace="http://ws.test.matt.com/")

if you don't specify any targetNamespace the package will be used.

Garis Suero
Ok I see that but how does that allow me to use the MyWSResponse tag in the soap message? Because in reality http://ws.test.matt.com doesn't actually exist so how does it know what to use for the element names? The reason why I'm asking is because I've used other webservices and they have different element names inside the soap:Body element and I was wondering how they achieved that?
controlfreak123
Tried adding the targetNamespace attribute to WebResult annotation and set it blank ? like targetNamespace="" ???
Garis Suero
That did nothing :(
controlfreak123
Nothing more to say, than try searching with "remove namespace prefix from generated wsdl"
Garis Suero