我必须实现一个web服务接口,并已提供了以下响应SOAP消息:JAX-WS和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消息:
<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,以便响应消息符合提到的肥皂消息 – maress
好吧,我想我现在明白你在做什么。您需要公开Web服务,并且返回的响应需要与问题中列出的第一个响应的响应相匹配。但是你回来的信息与第一个回复不一样。 –