Business 类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using ApplicationDataServices.SBEntityBox;

namespace ApplicationManagementLayer.Affiliate
{
    public class Amazon
    {
        private int ItemPage { get; set; }
        public int TotalNumberOfItem { get; set; }

public Amazon()
{
    ItemPage = 1;
    TotalNumberOfItem = 0;
}

 
string XMLURL = string.Empty;

 public async Task<AmazonRootobject> getProductsByKeywords(string q, Dictionary<string, string> CategoryNames, int ItemPage, string categorynamebyid)
{
    try
    {
        AWSSignedRequestHelper helper = new AWSSignedRequestHelper("para1", "para2", "webservices.amazon.in", "para3");
        IDictionary<string, string> r1 = new Dictionary<string, String>();
        r1["Service"] = "AWSECommerceService";

        r1["Operation"] = "ItemSearch";

        if (CategoryNames != null && CategoryNames.Any() && CategoryNames.Where(o => o.Key.Equals("AmazonCategoryName")).Any())
            r1["SearchIndex"] = CategoryNames.Where(o => o.Key.Equals("AmazonCategoryName")).First().Value;
        else
            r1["SearchIndex"] = "All";

        if (!r1["SearchIndex"].Equals("All") && CategoryNames != null && CategoryNames.Any() && CategoryNames.Where(o => o.Key.Equals("AmazonReferenceCategoryId")).Any())
            r1["BrowseNode"] = CategoryNames.Where(o => o.Key.Equals("AmazonReferenceCategoryId")).First().Value;

        if (!string.IsNullOrEmpty(q))
            r1["Keywords"] = q;
        else if (!string.IsNullOrEmpty(categorynamebyid))
            r1["Keywords"] = categorynamebyid;
        else if (CategoryNames != null && CategoryNames.Any() && CategoryNames.Where(o => o.Key.Equals("AmazonCategoryName")).Any())
            r1["Keywords"] = CategoryNames.Where(o => o.Key.Equals("AmazonCategoryName")).First().Value;
        else
            return null;

        r1["ResponseGroup"] = "Images,ItemAttributes,OfferFull,Offers,Variations";
        r1["Version"] = "2013-08-01";
        r1["ItemPage"] = ItemPage.ToString();
        //r1["Sort"] = "salesrank";

        string strRequestUrl = helper.Sign(r1);

        string output = null;
        using (System.Net.Http.HttpClient wc = new System.Net.Http.HttpClient())
        {
            var request = new System.Net.Http.HttpRequestMessage()
            {
                RequestUri = new Uri(strRequestUrl),
                Method = System.Net.Http.HttpMethod.Get,
            };

            /*var task =*/
            await wc.SendAsync(request)
                .ContinueWith((taskwithmsg) =>
                {
                    var response = taskwithmsg.Result;

                    var jsonTask = response.Content.ReadAsStringAsync();
                    jsonTask.Wait();
                    output = jsonTask.Result;
                });
            //task.Wait();

        }

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(output);
        string outputJson = XmlToJSON(doc);

        var pro = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<AmazonRootobject>(outputJson);
        TotalNumberOfItem = !string.IsNullOrEmpty(pro.ItemSearchResponse.Items.TotalResults) ? Convert.ToInt32(pro.ItemSearchResponse.Items.TotalResults) : 0;
        return pro;
        //return "";
    }
    catch
    {
        return null;
    }
}

http://stackoverflow.com/documentation/amazon-web-services/drafts/87373#
 

    }
}