0

我尝试连接到 Amazon AWSECommerceService。我使用 CXF 生成客户端类并提供 WSDL,但我收到错误消息“操作 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>
            <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>
    </soap:Body>
</soap:Envelope>

看起来有一个意想不到的标签

<ns1:itemLookup
                xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">

第二个示例在使用 SoapUI 时效果很好。出了什么问题?我在运行 wsdl2java maven 插件时缺少什么?

如果问题很愚蠢,请原谅我。我对 web 服务和 SOAP 真的很陌生。

当我添加注释时:

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

我收到消息:

<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>

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

4

2 回答 2

0

在您的 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)

到你的班级

于 2013-10-04T03:37:49.377 回答
0

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

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_KP 愿意提供帮助。

于 2013-10-04T17:49:50.487 回答