2013-10-03 20 views
0

我嘗試連接到Amazon AWSECommerceService。我使用CXF生成了客戶端類並提供了WSDL,但出現錯誤「操作itemLookup對此端點無效」。連接Amazon AWSECommerceService時無效的SOAP消息

一些調查把我帶到了這一點: 生成的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> 

這些名稱怪異我。

回答

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爲您提供幫助的意願。

0

在您的ItemLookup.java文件所在的包中,驗證是否存在package-info.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

哎呀錯誤地解釋你的問題。下面是解

添加註釋

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 

到類

+0

哪一個?服務本身或ServicePortType類?我會在晚上在家檢查解決方案,謝謝你的回答。 –

+0

服務本身 –

+0

它沒有工作:(。信息改變了,但不是預期的方式。 –