0

I'm trying to get use the new product amazon API to search for products on Amazon. I've been looking at their sample code and other people's examples of this but I'm not getting back any results and wondering if anyone else has used the API recently and could provide some assistance?

using System;
using System.ServiceModel;
using Simple.Amazon.ECS;

namespace Simple {
    class Program {
        // your Amazon ID's
        private const string accessKeyId = "*******************";
        private const string secretKey = "************************************";

        // the program starts here
        static void Main(string[] args) {

            // create a WCF Amazon ECS client
            BasicHttpBinding binding        = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.MaxReceivedMessageSize  = int.MaxValue;
            AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
                binding,
                new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

            // add authentication to the ECS client
            client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

            // prepare an ItemSearch request
            ItemSearchRequest request   = new ItemSearchRequest();
            request.SearchIndex         = "Books";
            request.Title               = "WCF";
            request.ResponseGroup       = new string[] { "Small" };

            ItemSearch itemSearch       = new ItemSearch();
            itemSearch.Request          = new ItemSearchRequest[] { request };
            itemSearch.AWSAccessKeyId   = accessKeyId;

            // issue the ItemSearch request
            ItemSearchResponse response = client.ItemSearch(itemSearch);

            // write out the results
            foreach (var item in response.Items[0].Item) {
                Console.WriteLine(item.ItemAttributes.Title);
            }
        }
    }
}

All the samples/examples are similar to this in structure but when it comes to the foreach loop there are no items returned(Null) so I get a null exception error.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Standage
  • 1,517
  • 7
  • 22
  • 41
  • 1
    What exactly does the `response` contain? – Jonathan Spooner Nov 07 '11 at 21:32
  • "Object reference not set to an instance of an object". When it reaches the foreach loop. – Standage Nov 07 '11 at 22:10
  • Wish I could tell you what's wrong. I've run the code which I downloaded from[1] and it runs as expected. [1] http://flyingpies.wordpress.com/2009/08/01/17/ – Jonathan Spooner Nov 07 '11 at 23:01
  • Yeah I've downloaded the sample from there as well and just added my access key and secret key and it falls over, very frustrating if you've just done it and it works for you. – Standage Nov 07 '11 at 23:26
  • Adding itemSearch.AssociateTag = ""; into the code seems to have solved the issue and I'm fetching back results. – Standage Nov 08 '11 at 17:40
  • A recent change of the API (see the [announce](https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html)) indicates that AssociateTag is now required and will be verified. So it's likely that old code will have to be changed to conform to this new requirement. – fmr Nov 14 '11 at 18:03
  • I realize this is post is somewhat old, but I'm having exactly the same problem. I used fiddler to examine the response and I see "...... but I also get null when ItemSearch returns. If I go to Debug-> Exceptions and enable exceptions I get "Could not load file or assembly 'AmazonSOAP.XmlSerializers" FileNotFoundException. Did you ever resolve this problem? Have you used fiddler? – John Russell Mar 16 '12 at 02:21
  • I orginally fixed this by adding in the AssociateTag which is a requirement now, but since the new Web service went live I couldn't my application to work and started again using this download:http://aws.amazon.com/code/Product-Advertising-API/2481, I had to make changes to get it to work though, The main one changing the namespace to: http://webservices.amazon.com/AWSECommerceService/2011-08-01 – Standage Mar 16 '12 at 15:31
  • I compiled a fix for this API sample. Please find it here: https://forums.aws.amazon.com/message.jspa?messageID=440527#440527 – bugnuker Apr 08 '13 at 19:38

2 Answers2

1

if the solution above still won't work.

try this one..

download the sample code on http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx

we need to update service references, make little change at app.config, program.cs, and reference.cs.

app.config: (1.) appSettings tag; assign accessKeyId and secretKey value, add . (2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag; assign accessKeyId and secretKey value. (3.) bindings tag -> basicHttpBinding tag; (optional) delete binding tag except AWSECommerceServiceBindingNoTransport and AWSECommerceServiceBindingTransport. (4.) client tag; delete endpoint tag except AWSECommerceServiceBindingTransport.

program.cs: add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

reference.cs: (open file in service references folder using visual studio) change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField; change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}

finally we can run our program and it will work. good luck..

nb: i use microsoft visual studio 2010. there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
0

This is a wsdl error, I use link below to fix it: https://forums.aws.amazon.com/thread.jspa?threadID=86989

Andy
  • 155
  • 1
  • 3
  • 12