我有一个非常简单的Web服务实现,如下所示
package implementation;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class WhatsMyName {
@WebMethod
public String getMyName(){
return "John Smith";
}
}
我在我的实现类文件上运行了一个wsgen来生成JAXB类和WSDL(以及XSD)
尝试调用此方法时的SOAP响应如下所示
<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>
如果我想生成如下所示的响应,我该怎么办
<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>
我确实尝试将生成的(通过wsgen)JAXB响应类更改为@XmlType(name =“NameResponse”,namespace =“http://implementation/”)和@XmlRootElement(name =“NameResponse”,namespace =“ http://implementation/“)但肥皂反应xml仍然保持不变。
每当我尝试将同一响应类中的@XmlElement(name =“return”,namespace =“”)更改为@XmlElement(name =“Name”,namespace =“”)时,我得到以下运行时错误执行发布此Web服务的发布者。
WebServiceException: class implementation.jaxws.GetMyNameResponse do not have a property of the name return
我刚开始学习SOAP而且我确实谷歌这个例外,但没有富有成效的解决方案。
答案 0 :(得分:1)
我认为您正在寻找注释@WebResult
。
在这种情况下,代码可以是
@WebService
public class WhatsMyName {
@WebMethod
@WebResult(name = "Name")
public String getMyName(){
return "John Smith";
}