使用Java的Amazon Product Advertising API请求

时间:2013-12-15 01:36:03

标签: java amazon javamail amazon-product-api

嗨我的代码是

// Initialize Web Service
            HandlerResolver handlerResolver=new AwsHandlerResolver(credentials.getAWSSecretKey());
            AWSECommerceService service = new AWSECommerceService();
            service.setHandlerResolver(handlerResolver); 
            // Create Web Service Connection
            AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

            // Add Parameters for the Item Lookup
            ItemLookupRequest itemLookup = new ItemLookupRequest();
            itemLookup.setIdType("ASIN");
            itemLookup.getItemId().add("B000RE216U");

            // Wrap Request in Lookup Body 
            ItemLookup lookup = new ItemLookup();
            lookup.setAWSAccessKeyId(credentials.getAWSAccessKeyId());
            lookup.getRequest().add(itemLookup);

            ItemLookupResponse response = port.itemLookup(lookup);

            System.out.println("response: " + response.toString());

我一直认为错误无法从Void转换为AWSECommerceService。我安装并配置了AWSHandlerResolver文件和编解码器jar。

错误讯息:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://webservices.amazon.com/AWSECommerceService/2010-11-01}AWSECommerceService is not a valid service. Valid services are: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}AWSECommerceService
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at com.ECS.client.jax.AWSECommerceService.<init>(AWSECommerceService.java:46) 

我一直在网上搜索。我可能必须更改AWSECommerceService的目标名称空间。但是找不到怎么样。请帮帮我

1 个答案:

答案 0 :(得分:0)

您正在为Webservice客户端及其端口使用错误的命名空间(实际上是错误的WS版本)。

转到AWSECommerceServiceAWSECommerceServicePortType类,并将所有名称空间http://webservices.amazon.com/AWSECommerceService/2010-11-01替换为http://webservices.amazon.com/AWSECommerceService/2013-08-01