gpt4 book ai didi

Java网络服务: null request parameter

转载 作者:行者123 更新时间:2023-12-01 09:53:03 27 4
gpt4 key购买 nike

我基于现有的第 3 方 .NET Web 服务创建了一个 Java Web 服务。这是我的网络服务界面:

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 消息包含响应参数的命名空间(这是来自第 3 方 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>

包信息.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 服务出了什么问题?

最佳答案

您是否未能将package-info.class包含在您的存档中?

由于不工作的情况(包括 TNS)与 JAX-WS @WebParam 匹配,我想知道您是否生成了带有 elementFormDefault="qualified"的 JAXB(您通常可以在 package-info.java 中看到这一点),但可能失败了将它们压缩(或将它们加载到 JAXBContext 中),这可能会将 elementFormDefault 默认为不合格

如果这没有帮助,也许粘贴 WSDL/XSD 并解释如何生成 JAX-WS 和 JAXB 带注释的类会有所帮助。使用wsimport

关于Java网络服务: null request parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37483189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com