Web Services 连接Amazon AWSECommerceService时的SOAP消息无效

omqzjyyz  于 2023-03-19  发布在  其他
关注(0)|答案(2)|浏览(194)

我尝试连接到Amazon AWSECommerceService。我使用CXF生成了客户端类并提供了WSDL,但我得到了一个错误“The action itemLookup is not valid for this endpoint”。
一些调查使我想到这一点:生成的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插件时我错过了什么?
请原谅我的问题是愚蠢的。我真的是新的网络服务和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>

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

643ylb08

643ylb081#

在www.example.com文件所在的包中ItemLookup.java,验证是否存在package-info.java,如果不存在,则创建一个。

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

去你的班级

hfwmuf9z

hfwmuf9z2#

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

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());

成功了。2感谢@SRT_KP的帮助。

相关问题