Reputation: 1726
I have a very simple web service implementation as shown below
package implementation;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class WhatsMyName {
@WebMethod
public String getMyName(){
return "John Smith";
}
}
I ran a wsgen on my implementation class file to generate JAXB classes and WSDLs ( along with XSD )
The SOAP response when i try calling this method is as below
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getMyNameResponse xmlns:ns2="http://implementation/">
<return>John Smith</return>
</ns2:getMyNameResponse>
</S:Body>
</S:Envelope>
What should i do if i want to generate a response like below
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:NameResponse xmlns:ns2="http://implementation/">
<Name>John Smith</Name>
</ns2:NameResponse>
</S:Body>
</S:Envelope>
I did try changing the generated ( by wsgen) JAXB response class to have @XmlType(name = "NameResponse", namespace = "http://implementation/") and @XmlRootElement(name = "NameResponse", namespace = "http://implementation/") but the soap response xml still remains the same.
Whenever i try to change @XmlElement(name = "return", namespace = "") in the same response class to @XmlElement(name = "Name", namespace = ""), i get the below runtime error while executing the publisher that publishes this web service impl.
WebServiceException: class implementation.jaxws.GetMyNameResponse do not have a property of the name return
I just started learning SOAP and i did google this exception but with no fruitful solution.
Upvotes: 0
Views: 756
Reputation: 120
I think you are looking for the annotation @WebResult
.
In this case the code could be
@WebService
public class WhatsMyName {
@WebMethod
@WebResult(name = "Name")
public String getMyName(){
return "John Smith";
}
Upvotes: 1