【发布时间】:2013-12-18 20:14:10
【问题描述】:
我必须实现一个 web 服务接口,并且提供了以下响应 SOAP 消息:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENC:encodingStyle="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:NS2="urn:WebserviceIntf">
<NS1:VoidPaymentResponse xmlns:NS1="urn:WebserviceIntf-Webservice">
<return href="#1"/>
</NS1:VoidPaymentResponse>
<NS2:TVoidPaymentResponse id="1" xsi:type="NS2:TVoidPaymentResponse">
<MessageCode xsi:type="xsd:string">00</MessageCode>
<MessageDescription xsi:type="xsd:string">Successful</MessageDescription>
</NS2:TVoidPaymentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这就是我所拥有的接口 web 方法。
@WebMethod(operationName = "VoidPayment")
@ResponseWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
@RequestWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
public VoidPaymentDetailResponse voidPayment(
@WebParam(name = "LoginID") String loginId,
@WebParam(name = "Password") String password,
@WebParam(name = "TransactionID") String transactionId,
@WebParam(name = "Echo") String additionalInformation,
@WebParam(name = "TVoidPaymentResponse", mode = WebParam.Mode.INOUT, targetNamespace = "urn:WebserviceIntf") Holder<VoidPaymentDetail> voidPaymentDetails) {
VoidPayment vp = new VoidPayment(loginId, password, transactionId, additionalInformation);
VoidPaymentDetail vpd = voidPayment(vp);
voidPaymentDetails.value = vpd;
return new VoidPaymentDetailResponse("#" + vpd.getId());
}
当我在 SOAPUI 上测试我的 web 方法时。我收到以下肥皂消息:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns3:VoidPaymentResponse xmlns:ns2="http://payapi.afrocoin.com/" xmlns:ns3="urn:WebserviceIntf-Webservice" xmlns:ns4="urn:WebserviceIntf">
<return href="#Od4dY"/>
<ns4:TVoidPaymentResponse id="Od4dY">
<MessageCode>32</MessageCode>
<MessageDescription>Login failed</MessageDescription>
</ns4:TVoidPaymentResponse>
</ns3:VoidPaymentResponse>
</soap:Body>
</soap:Envelope>
显然这两条消息之间存在差异,我需要完全遵守预期的响应。 我需要在 web 方法中添加哪些注释以确保发生这种情况。
我花了无数个小时试图弄清楚这一点。
附加代码:
@XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetailResponse {
@XmlAttribute(name = "href")
private String paymentDetail;
public VoidPaymentDetailResponse() {
}
public VoidPaymentDetailResponse(String paymentDetail) {
this.paymentDetail = paymentDetail;
}
public String getPaymentDetail() {
return paymentDetail;
}
public void setPaymentDetail(String paymentDetail) {
this.paymentDetail = paymentDetail;
}
}
@XmlType(name = "TVoidPaymentResponse", namespace = "urn:WebserviceIntf")
@Entity
@Table(name = "VoidPaymentResponseDetails")
@XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetail implements Serializable {
private static final long serialVersionUID = 19383656L;
@Id
@XmlTransient
private Long detailId = IdGenerator.generateId();
@XmlAttribute
@XmlID
@Transient
private String id = IdGenerator.generateIdentifier(5);
@XmlElement(name = "MessageCode")
private String messageCode;
@XmlElement(name = "MessageDescription")
private String messageDescription;
@XmlTransient
@OneToOne
private VoidPayment voidPaymentRequest;
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public Long getDetailId() {
return detailId;
}
public void setDetailId(Long detailId) {
this.detailId = detailId;
}
public VoidPayment getVoidPaymentRequest() {
return voidPaymentRequest;
}
public void setVoidPaymentRequest(VoidPayment voidPaymentRequest) {
this.voidPaymentRequest = voidPaymentRequest;
}
public String getMessageCode() {
return messageCode;
}
public void setMessageCode(String messageCode) {
this.messageCode = messageCode;
}
public String getMessageDescription() {
return messageDescription;
}
public void setMessageDescription(String messageDescription) {
this.messageDescription = messageDescription;
}
}
我正在使用默认的 jboss wsimport。
谢谢
【问题讨论】:
-
1.您可以使用 wsimport 发布您正在导入的 wsdl 吗?
-
不,我是生成 wsdl 的人,以便响应消息符合提到的肥皂消息
-
好的,我想我现在明白你想要做什么了。您需要公开一个 Web 服务,并且返回的响应需要与问题中列出的第一个响应的响应相匹配。但是您返回的消息与第一个响应不同。
-
@ChrisHinshaw 完全正确
-
您尝试克隆的消息上下文是否具有包含命名空间和所有内容的 wsdl?这将是开始的正确位置,因为您可以导入该 wsdl,并且您将已经为 VoidPaymentResponse 对象配置了正确的名称空间。否则你将不得不使用 jaxb 和 jax-ws 注释。
标签: java web-services soap jboss jax-ws