Java 从端口';返回类而不是void;s法

Java 从端口';返回类而不是void;s法,java,soap,cxf,soap-client,webservice-client,Java,Soap,Cxf,Soap Client,Webservice Client,我是SOAP服务的初学者。我有一个使用一些SOAP方法的用例。因此,为此,我编写了一个客户端,以获取一些服务端口的方法数据 目前,我从导入的WSDL中意识到,特定的服务方法具有void返回类型。但是,我希望有返回端口方法。例如: 这是WSDL的当前行为: SomeService ss = new SomeService(); ProxyPort port = ss.getPort(); port.IdentifyBaggage(identifyBaggageIndicators,

我是SOAP服务的初学者。我有一个使用一些SOAP方法的用例。因此,为此,我编写了一个客户端,以获取一些服务端口的方法数据

目前,我从导入的WSDL中意识到,特定的服务方法具有void返回类型。但是,我希望有返回端口方法。例如:

这是WSDL的当前行为:

SomeService ss = new SomeService();
ProxyPort port = ss.getPort();
port.IdentifyBaggage(identifyBaggageIndicators,
                bagTagDetailsTopLevel, baggageGroupInfo, flightDetailsResponse, quantityDetails, dummySegment);
然而,我想要的行为是:

SomeService ss = new SomeService();
ProxyPort port = ss.getPort();
BaggageReply reply= port.IdentifyBaggage(identifyBaggageIndicators,
                bagTagDetailsTopLevel, baggageGroupInfo, flightDetailsResponse, quantityDetails, dummySegment);
我尝试在SEI中添加返回类型,但它提供了:

线程“main”java.lang.ClassCastException中的异常: java.util.ArrayList无法在处强制转换为bla.bla.bla.BaggageReply com.sun.proxy.$Proxy46.IdentifyBaggage(未知来源)

SEI看起来像这样:

/**
    * @param identifyBaggageIndicators
    * @param bagTagDetails
    * @param baggageGroupInfo
    * @param routingDetails
    * @param historicalDays
    * @param dummy
    */
   @WebMethod(operationName = "IdentifyBaggage", action = "http://webservices.amadeus.com/endpoint1")
   @RequestWrapper(localName = "IdentifyBaggage", targetNamespace = "http://xml.amadeus.com/endpoint1", className = "com.amadeus.xml.bla_bla.IdentifyBaggage")
   @ResponseWrapper(localName = "BaggageReply", targetNamespace = "http://xml.amadeus.com/endpoint2", className = "com.amadeus.xml.bla1_bla1.BaggageReply")
   public void dcsbagIdentifyBaggage(
       @WebParam(name = "identifyBaggageIndicators", targetNamespace = "http://some.host.com/endpoint1")
       List<StatusTypeI> identifyBaggageIndicators,
       @WebParam(name = "bagTagDetails", targetNamespace = "http://some.host.com/endpoint1")
       BaggageInformationTypeI bagTagDetails,
       @WebParam(name = "baggageGroupInfo", targetNamespace = "http://xml.amadeus.com/endpoint1")
       IdentifyBaggage.BaggageGroupInfo baggageGroupInfo,
       @WebParam(name = "routingDetails", targetNamespace = "http://xml.amadeus.com/endpoint1")
       FlightDetailsResponseType routingDetails,
       @WebParam(name = "historicalDays", targetNamespace = "http://xml.amadeus.com/endpoint1")
       NumberOfUnitsType historicalDays,
       @WebParam(name = "dummy", targetNamespace = "http://xml.amadeus.com/endpoint2", mode = WebParam.Mode.OUT)
               com.amadeus.xml.bla_bla.DummySegmentTypeI dummy);
/**
*@param identificationbaggageindicators
*@param bagTagDetails
*@param baggageGroupInfo
*@param路由详细信息
*@param historicalDays
*@param-dummy
*/
@WebMethod(operationName=“IdentifyBaggage”,操作=”http://webservices.amadeus.com/endpoint1")
@RequestWrapper(localName=“IdentifyBaggage”,targetNamespace=”http://xml.amadeus.com/endpoint1,className=“com.amadeus.xml.bla_bla.identificationBaggage”)
@ResponseWrapper(localName=“BaggageReply”,targetNamespace=”http://xml.amadeus.com/endpoint2,className=“com.amadeus.xml.bla1_bla1.BaggageReply”)
公共无效DCSBAgIdentificationBaggage(
@WebParam(name=“IdentificationBaggageIndicators”,targetNamespace=”http://some.host.com/endpoint1")
列出识别行李指示灯,
@WebParam(name=“bagTagDetails”,targetNamespace=”http://some.host.com/endpoint1")
行李信息类型I行李详情,
@WebParam(name=“baggageGroupInfo”,targetNamespace=”http://xml.amadeus.com/endpoint1")
IdentificationBaggage.BaggageGroupInfo BaggageGroupInfo,
@WebParam(name=“routingDetails”,targetNamespace=”http://xml.amadeus.com/endpoint1")
航班详情响应类型路由详情,
@WebParam(name=“historicalDays”,targetNamespace=”http://xml.amadeus.com/endpoint1")
历史天数的单位数,
@WebParam(name=“dummy”,targetNamespace=”http://xml.amadeus.com/endpoint2,mode=WebParam.mode.OUT)
com.amadeus.xml.bla_bla.DummySegmentTypeI dummy);

添加返回类型的方法是什么?

似乎您是在首先进行契约(您有一个WSDL作为起点)SOAP客户端开发

您必须连接到某个地方,并且服务是“静态的”(无法更改)

1,如果SOAP服务无法更改(例如,因为它不是您的服务),并且您拥有的WSDL是正确的(由正在运行的服务生成),那么您不能这样做

2,如果您拥有的WSDL已经过时,并且您看到了WSDL中没有的返回类型,只需获取新的WSDL,生成另一个客户机类并使用它们即可

您必须连接到属于您的服务(客户端和服务器端均由您开发)

这是更有趣的部分,这里我们有两种不同的方式:

1,合同优先web服务开发(我更喜欢这个)

您通过每个操作和complextype从头创建了一个WSDL。 您必须创建一个新的BaggageReply complextype,并修改与此类似的操作(随机wsdl示例):


键是和定义的类(在输出标记的message属性中)。 然后重新生成客户端和服务器端,更新serverimpl,并正确实现客户端

2,代码优先开发(您已经开始编写自己的java类)

在这种情况下,您是一名熟练的开发人员,非常了解如何做到这一点:) 假设您有服务器端代码,我将复制输入类(com.amadeus.xml.bla_bla.IdentifyBaggage)将其重命名为输出类,并更新本地名称和QName的命名空间、成员、setter/getter等,并将操作的void返回值替换为该类。 最后一件事是更新操作或webmethod以在最后返回BaggageReply。
当然,您的客户也必须进行修改,才能在回复中做出一些东西。

令人困惑的描述。如果
void
的返回类型是
dcsbagbaggagerply
,那么它怎么可能是该方法的返回类型呢?仍然找不到解决方案!
    <message name="GetLastTradePriceInput">
        <part name="body" element="xsd1:TradePriceRequest"/>
    </message>

    <message name="GetLastTradePriceOutput">
        <part name="body" element="xsd1:TradePrice"/>
    </message>

    <portType name="StockQuotePortType">
        <operation name="GetLastTradePrice">
           <input message="tns:GetLastTradePriceInput"/>
           <output message="tns:GetLastTradePriceOutput"/>
        </operation>
    </portType>