Soap消息响应体修改帮助
我一直在使用 jbossws-cxf 尝试 Web 服务。我认为问题不在于我正在使用的实现,而在于代码的生成方式。这是我的 pojo,其中包含 Web 服务的注释。
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)];
}
}
当我测试Web服务(使用soapUI)时,我的soap响应是,
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getStatusResponse xmlns:ns2="http://ws.test.matt.com/">
<status>Hello</status>
</ns2:getStatusResponse>
</soap:Body>
</soap:Envelope>
是否有办法手动编辑wsdl文件来修改“ns2”的命名空间,以便我可以将响应包装在不同的标签中。我想要的是类似
<soap:Envelope ...>
<soap:Body>
<MyWSResponse xmlns="http://ws.test.matt.com/">
<status>Hello</status>
</MyWSResponse>
<soap:Body>
<soap:Envelope>
我没有使用的注释可以修改它吗?到目前为止,我还没有找到一种方法来修改 wsdl。
更新:将 @WebService
更改为 @WebService(targetNamespace="http://MyWSResponse")
将肥皂请求更改为正确的标记,但肥皂响应消息仍然使用 ns2 MyWSResponse 的。
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/">
<soap:Body>
<ns2:getStatusResponse xmlns:ns2="http://ws.test.matt.com/">
<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/">
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须向
WebService
注释添加新的attribute
,如下所示:如果您未指定任何
targetNamespace
,则package
将被使用。You must add a new
attribute
to theWebService
annotation as:if you don't specify any
targetNamespace
thepackage
will be used.