AmazonMWS1.GetMatchingProduct.InvokeGetMatchingProductForId C# (CSharp) Méthode

InvokeGetMatchingProductForId() public static méthode

public static InvokeGetMatchingProductForId ( MarketplaceWebServiceProducts service, MarketplaceWebServiceProducts.Model.GetMatchingProductForIdRequest request ) : void
service MarketplaceWebServiceProducts
request MarketplaceWebServiceProducts.Model.GetMatchingProductForIdRequest
Résultat void
        public static void InvokeGetMatchingProductForId(MarketplaceWebServiceProducts service,
                                                         GetMatchingProductForIdRequest request)
        {
            try{
                GetMatchingProductForIdResponse response = service.GetMatchingProductForId(request);

                List<GetMatchingProductForIdResult> getMatchingProductForIdResultList =
                    response.GetMatchingProductForIdResult;
                foreach (
                    GetMatchingProductForIdResult getMatchingProductForIdResult in getMatchingProductForIdResultList){
                    ProductList products = getMatchingProductForIdResult.Products;
                    List<Product> productList = products.Product;

                    foreach (Product product in productList){
                        if (getMatchingProductForIdResult.IsSetProducts()){
                            if (product.IsSetAttributeSets()){
                                //Binding, Format, ASIN, Height, Length, Width, Weight, Product Group, Small Image URL, Title, Sales Rank

                                foreach (var attribute in product.AttributeSets.Any){
                                    string xml = ProductsUtil.FormatXml((System.Xml.XmlElement) attribute);

                                    XElement element = XElement.Parse(xml);

                                    XNamespace ns2 =
                                        "http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd";
                                    title = element.Element(ns2 + "Title").Value;
                                    binding = element.Element(ns2 + "Binding").Value;
                                    productGroup = element.Element(ns2 + "ProductGroup").Value;
                                    smallImageUrl =
                                        element.Element(ns2 + "SmallImage").Element(ns2 + "URL").Value;
                                    height = element.Element(ns2 + "ItemDimensions").Element(ns2 + "Height").Value;
                                    length = element.Element(ns2 + "ItemDimensions").Element(ns2 + "Length").Value;
                                    width = element.Element(ns2 + "ItemDimensions").Element(ns2 + "Width").Value;
                                    weight = element.Element(ns2 + "ItemDimensions").Element(ns2 + "Weight").Value;
                                }
                            }

                            if (product.IsSetIdentifiers()){
                                IdentifierType identifier = product.Identifiers;
                                if (identifier.IsSetMarketplaceASIN()){
                                    ASINIdentifier marketplaceASIN = identifier.MarketplaceASIN;
                                    if (marketplaceASIN.IsSetASIN()){
                                        ASIN = marketplaceASIN.ASIN;
                                    }
                                }
                            }

                            if (product.IsSetSalesRankings()){
                                int i = 0;
                                SalesRankList rankings = product.SalesRankings;
                                List<SalesRankType> salesRankList = rankings.SalesRank;
                                foreach (SalesRankType saleRankings in salesRankList){
                                    for (; i < 1; i++){
                                        if (saleRankings.IsSetRank()){
                                            salesRank = Convert.ToString(saleRankings.Rank);
                                        }
                                    }
                                }
                            }
                            Console.WriteLine("Height: {0} \nLength: {1} \nWidth: {2} " +
                                              "\nWeight: {3} \nBinding: {4} \nProduct Group: {5} " +
                                              "\nURL: {6} \nTitle: {7} \nASIN: {8} \nSale Rank: {9} \n",
                                              height, length, width, weight, binding, productGroup, smallImageUrl,
                                              title, ASIN, salesRank);
                        }
                    }
                }
            }
            catch (MarketplaceWebServiceProductsException ex){
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }