Java 连接Amazon AWSECommerceService时,SOAP消息无效

Java 连接Amazon AWSECommerceService时,SOAP消息无效,java,web-services,cxf,amazon,Java,Web Services,Cxf,Amazon,我尝试连接亚马逊AWSecommercService。我使用CXF生成了客户机类,并提供了WSDL,但我得到一个错误“action itemLookup对此端点无效” 一些调查让我想到了这一点: 生成的SOAP消息如下所示: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns1:itemLookup

我尝试连接亚马逊AWSecommercService。我使用CXF生成了客户机类,并提供了WSDL,但我得到一个错误“action itemLookup对此端点无效”

一些调查让我想到了这一点: 生成的SOAP消息如下所示:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:itemLookup
            xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">
            <ItemLookup
                xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
                <AssociateTag>pkd</AssociateTag>
                <Request>
                    <IdType>ISBN</IdType>
                    <ItemId>0321534468</ItemId>
                    <SearchIndex>Books</SearchIndex>
                </Request>
            </ItemLookup>
        </ns1:itemLookup>
    </soap:Body>
</soap:Envelope>
我得到了信息:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:itemLookup
            xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">
            <ns2:ItemLookup
                xmlns:ns2="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/"
                xmlns:ns3="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
                <AssociateTag>pkd</AssociateTag>
                <Shared>
                    <IdType>ISBN</IdType>
                    <ItemId>0321534468</ItemId>
                    <SearchIndex>Books</SearchIndex>
                </Shared>
            </ns2:ItemLookup>
        </ns1:itemLookup>
    </soap:Body>
</soap:Envelope>

pkd
ISBN
0321534468
书

这些名称空间对我来说很奇怪。

在ItemLookup.java文件所在的包中,验证是否存在package-info.java,如果不存在,请创建一个。在package info类中,您的代码如下所示

@javax.xml.bind.annotation.XmlSchema(namespace = "hhttp://_2011_08_01.awsecommerceservice.webservices.amazon.com/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
    @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://_2011_08_01.awsecommerceservice.webservices.amazon.com/", prefix = "ns1")
})
package your.package;
因此,请尝试删除名称空间uri

Opps错误地解释了你的问题。这是解决办法

添加注释

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

对你们班来说

好的,我找到了解决办法。我不知道为什么会这样,但问题在于我创建服务的方式:

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(AWSECommerceServicePortType.class);
factory.setAddress("https://soap.amazon.com/onca/soap?Service=AWSECommerceService");
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
AWSECommerceServicePortType ss = (AWSECommerceServicePortType) factory.create();
但当我把它改成:

AWSECommerceServicePortType ss = new AWSECommerceService().getAWSECommerceServicePort();        
Client client = ClientProxy.getClient(ss);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());

成功了。感谢@SRT\u KP的帮助。

哪一位?服务本身还是ServicePortType类?晚上我会在家里检查解决方案,谢谢你的回答。它不起作用:(。消息改变了,但不是预期的方式。
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(AWSECommerceServicePortType.class);
factory.setAddress("https://soap.amazon.com/onca/soap?Service=AWSECommerceService");
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
AWSECommerceServicePortType ss = (AWSECommerceServicePortType) factory.create();
AWSECommerceServicePortType ss = new AWSECommerceService().getAWSECommerceServicePort();        
Client client = ClientProxy.getClient(ss);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());