我基于现有的第三方.NET Web服务创建了一个Java Web Service。这是我的网络服务界面:
package externalqueryadapter.service._01.responsereceiver;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import org.datacontract.schemas._2004._07.commonservices_externalqueryadapter.ExternalResponse;
@WebService(name = "ResponseReceiver", targetNamespace = "http://Service.ExternalQueryAdapter/01/ResponseReceiver")
@XmlSeeAlso({
externalqueryadapter.service._01.responsereceiver.ObjectFactory.class,
org.datacontract.schemas._2004._07.commonservices_externalqueryadapter_contract.ObjectFactory.class
})
public interface ResponseReceiver {
@WebMethod(operationName = "ReceiveResponse")
@RequestWrapper(localName = "ReceiveResponse", targetNamespace = "http://Service.ExternalQueryAdapter/01/ResponseReceiver", className = "externalqueryadapter.service._01.responsereceiver.ReceiveResponse")
@ResponseWrapper(localName = "ReceiveResponseResponse", targetNamespace = "http://Service.ExternalQueryAdapter/01/ResponseReceiver", className = "externalqueryadapter.service._01.responsereceiver.ReceiveResponseResponse")
@Action(input = "http://Service.ExternalQueryAdapter/01/ResponseReceiver/ResponseReceiver/ReceiveResponseRequest", output = "http://Service.ExternalQueryAdapter/01/ResponseReceiver/ResponseReceiver/ReceiveResponseResponse")
public void receiveResponse(
@WebParam(name = "response", targetNamespace = "http://schemas.datacontract.org/2004/07/CommonServices.ExternalQueryAdapter.Contract")
ExternalResponse response);
}
我的ExternalResponse课程
package org.datacontract.schemas._2004._07.commonservices_externalqueryadapter_contract;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "externalResponse", propOrder = {
"requestTime",
"userID"
})
public class ExternalResponse {
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar requestTime;
protected String userID;
public XMLGregorianCalendar getRequestTime() {
return requestTime;
}
public void setRequestTime(XMLGregorianCalendar value) {
this.requestTime = value;
}
public String getUserID() {
return userID;
}
public void setUserID(String value) {
this.userID = value;
}
}
我成功地从Java WebService客户端接收SOAP消息,如下所示:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ReceiveResponse
xmlns="http://Service.ExternalQueryAdapter/01/ResponseReceiver">
<response
xmlns="">
<RequestTime>2013-01-30T20:00:00.000Z</RequestTime>
<userID>olololo</userID>
</response>
</ReceiveResponse>
</soapenv:Body>
</soapenv:Envelope>
但是如果SOAP消息包含响应参数的命名空间(它是来自第三方webService客户端的消息(我认为是.NET客户端)),我的Java WebService会在null
中收到ExternalResponse
响应。
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ReceiveResponse
xmlns="http://Service.ExternalQueryAdapter/01/ResponseReceiver">
<response
xmlns="http://schemas.datacontract.org/2004/07/CommonServices.ExternalQueryAdapter.Contract">
<RequestTime>2013-01-30T20:00:00.000Z</RequestTime>
<userID>olololo</userID>
</response>
</ReceiveResponse>
</soapenv:Body>
</soapenv:Envelope>
package-info.java:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.datacontract.org/2004/07/CommonServices.ExternalQueryAdapter.Contract", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.datacontract.schemas._2004._07.CommonServices_ExternalQueryAdapter_Contract;
我的Java Web服务有什么问题?
答案 0 :(得分:1)
您是否未能在档案中加入 package-info.class ?
由于非工作案例(包括TNS)与JAX-WS @WebParam匹配,我想知道你是否使用elementFormDefault =&#34; qualified&#34;生成了JAXB。 (你通常可以在package-info.java中看到这个),但可能无法将它们压缩(或将它们加载到JAXBContext中),这可能会将elementFormDefault默认为不合格
如果这没有帮助,可能有助于粘贴WSDL / XSD并解释如何生成JAX-WS和JAXB注释类。使用 wsimport ?