public ItemLookupResponse Lookup(ItemLookupRequest lookupRequest)
        {
            ItemLookup          lookup   = CreateItemLookup(lookupRequest);
            AWSECommerceService api      = GetService();
            ItemLookupResponse  response = api.ItemLookup(lookup);

            return(response);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // If you are using a debugging proxy like Fiddler to capture SOAP
            // envelopes, and you get SSL Certificate warnings, uncomment the
            // following line:
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            // Create an ItemLookup request, with ResponseGroup "Small"
            // and using the item ID provided above.
            ItemLookup itemLookup = new ItemLookup();

            itemLookup.AWSAccessKeyId = MY_AWS_ID;

            ItemLookupRequest itemLookupRequest = new ItemLookupRequest();

            itemLookupRequest.ItemId        = new String[] { ITEM_ID };
            itemLookupRequest.ResponseGroup = new String[] { "Small", "AlternateVersions" };
            itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };

            // create an instance of the serivce
            AWSECommerceService api = new AWSECommerceService();

            // set the destination
            api.Destination = new Uri(DESTINATION);

            // apply the security policy, which will add the require security elements to the
            // outgoing SOAP header
            AmazonHmacAssertion amazonHmacAssertion = new AmazonHmacAssertion(MY_AWS_ID, MY_AWS_SECRET);

            api.SetPolicy(amazonHmacAssertion.Policy());

            // make the call and print the title if it succeeds
            try
            {
                ItemLookupResponse itemLookupResponse = api.ItemLookup(itemLookup);
                Item item = itemLookupResponse.Items[0].Item[0];
                System.Console.WriteLine(item.ItemAttributes.Title);
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine(e);
            }

            // we're done
            System.Console.WriteLine("HMAC sample finished. Hit Enter to terminate.");
            System.Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // If you are using a debugging proxy like Fiddler to capture SOAP
            // envelopes, and you get SSL Certificate warnings, uncomment the
            // following line:
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            // create an ItemLookup request:
            ItemLookup itemLookup = new ItemLookup();

            itemLookup.AWSAccessKeyId = MY_AWS_ACCESS_KEY_ID;

            ItemLookupRequest itemLookupRequest = new ItemLookupRequest();

            itemLookupRequest.ItemId        = new String[] { "0545010225" };
            itemLookupRequest.ResponseGroup = new String[] { "Small", "AlternateVersions" };
            itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };

            // create service instance and set destination
            AWSECommerceService api = new AWSECommerceService();

            api.Destination = new Uri(DESTINATION);

            // set the policy so that all outgoing requests are signed with the certificate
            AmazonX509Assertion amazonX509Assertion = new AmazonX509Assertion(MY_AWS_CERT_NAME);

            api.SetPolicy(amazonX509Assertion.Policy());

            // fetch the response.
            ItemLookupResponse itemLookupResponse = api.ItemLookup(itemLookup);

            Item item = null;

            try {
                item = itemLookupResponse.Items[0].Item[0];
                System.Console.WriteLine(item.ItemAttributes.Title);
            } catch (Exception e) {
                System.Console.Error.WriteLine(e);
            }

            System.Console.WriteLine("X.509 sample finished. Hit Enter to terminate.");
            System.Console.ReadLine();
        }
        private void GetInfoFromISBN(string isbn, string technology)
        {
            if (isbn.Length != 10)
            {
                return;
            }

//		MultiOperation commerceService = new MultiOperation();

            AWSECommerceService commerceService = null;

            try
            {
                commerceService = new AWSECommerceService();
            }
            catch (Exception e)
            {
                lblStatus.Text = e.Message;
            }
            // AWSProductData productData = new AWSProductData();
            ItemLookup lookup = null;

            try
            {
                ItemLookupRequest req = new ItemLookupRequest();
                req.IdType    = ItemLookupRequestIdType.ASIN;
                req.ItemId    = new string[1];
                req.ItemId[0] = isbn;
                // req.SearchIndex = "Books";

                lookup = new ItemLookup();
                lookup.AssociateTag   = "libertyassocia00A";
                lookup.SubscriptionId = "0SD959SZV6KXV3BKE2R2";
                lookup.Request        = new ItemLookupRequest[1];
                lookup.Request[0]     = req;
            }
            catch (System.Exception e)
            {
                lblStatus.Text = e.Message;
            }


            ItemLookupResponse response;
            Items info;

            Item[] items;
            Item   item;



            int    salesRank = -1;
            string author    = string.Empty;
            string pubDate   = string.Empty;
            string publisher = string.Empty;
            string title     = string.Empty;
            string strURL    = string.Empty;

            try
            {
                response = commerceService.ItemLookup(lookup);
                // response = productData.ItemLookup( lookup );
                info      = response.Items[0];
                items     = info.Item;
                item      = items[0];
                salesRank = item.SalesRank == null ? -1 : Convert.ToInt32(item.SalesRank);
                author    = FixQuotes(item.ItemAttributes.Author[0]);
                pubDate   = FixQuotes(item.ItemAttributes.PublicationDate);
                publisher = FixQuotes(item.ItemAttributes.Publisher);
                title     = FixQuotes(item.ItemAttributes.Title);
                strURL    = item.DetailPageURL;
            }
            catch (System.Exception ex)
            {
                lblStatus.Text = ex.Message;
            }

            // update the list box
            string results = title + " by " + author + ": " +
                             publisher + ", " + pubDate + ". Rank: " + salesRank;

            lbOutput.Items.Add(results);
            lbOutput.SelectedIndex = lbOutput.Items.Count - 1;

            // update the database
            string commandString = @"Update BookInfo set isbn = '" +
                                   isbn + "', title = '" + title + "', publisher = '" +
                                   publisher + "', pubDate = '" + pubDate + "', rank = " +
                                   salesRank + ", link = '" + strURL + "', lastUpdate = '" +
                                   System.DateTime.Now + "', technology = '" +
                                   technology + "', author = '" +
                                   author + "' where isbn = '" +
                                   isbn + "'";

            command.CommandText = commandString;
            try
            {
                // if no rows were affected, this is a new record
                connection.Open();
                int numRowsAffected = command.ExecuteNonQuery();
                if (numRowsAffected == 0)
                {
                    commandString = @"Insert into BookInfo values ('" +
                                    isbn + "', '" + title + "', '" + publisher + "', '" +
                                    pubDate + "', '" + FixQuotes(strURL) + "', " + salesRank + ", '" +
                                    System.DateTime.Now +
                                    "', '" + technology + "', '" + author + "')";

                    command.CommandText = commandString;
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
                lbOutput.Items.Add("Unable to update database!");
                lbOutput.SelectedIndex = lbOutput.Items.Count - 1;
            }
            finally
            {
                connection.Close(); // clean up
            }
        }                           // close for GetInfoFromISBN