eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>使用SOAP协议的C#例程:GetProducts

技术文档

问题
使用SOAP协议的C#例程:GetProducts
解答
0
人觉得答案有帮助)

 

总述

GetProducts 的C# 例程:使用Visual Studio .NET (原始版本,非2003版或2005版) 和SOAP API


 

详细描述

下附的命令行例程包含了对GetProducts API 的调用。

 readme.txt 文件中包含了此项目的一些简单注释,请在使用例程时留意。

  下面是例程中实现API调用的主要代码片段:
 

  GetProductsRequestType Request = new GetProductsRequestType();
  // there are a significant number of ways this call can be used
  // some of the options are commented out, and can be activated
  // by commenting and uncommenting lines as directed
  // the ProductSearch container has the fields that forms the search query

  ProductSearchType search = new ProductSearchType();
  // if we wanted to do a general query on one or more keywords
  // we would indicate only the QueryKeywords input
  // if you wish to do this, uncomment the next 3 code lines
  // and comment out the 7 code lines below that set ExternalProductID and IncludeItemArray
  //search.QueryKeywords = "harry potter";
  // let's look for only products that have real items available
  //search.AvailableItemsOnlySpecified = true;
  //search.AvailableItemsOnly = true;
  // if we wanted to search for a specific
  // ISBN or UPC we would not use QueryKeywords
  // we would use ExternalProductID
  // for this example, we will use the UPC value 085392133123
  // which is a Harry Potter and the Sorcerer's Stone DVD

  ExternalProductIDType UPC = new ExternalProductIDType();
  UPC.TypeSpecified = true;
  UPC.Type = ExternalProductCodeType.UPC;
  UPC.Value = "085392133123";
  search.ExternalProductID = UPC;

  // let's include real items in the response
  Request.IncludeItemArraySpecified = true;
  Request.IncludeItemArray = true;

  // if you wish to include review details
  // then uncomment the next 2 lines
  // keep in mind that this is not applicable with QueryKeywords
  //Request.IncludeReviewDetailsSpecified = true;
  //Request.IncludeReviewDetails = true;
  // Set ProductSearchID if you wish to provide your own unique
  // identifier to this specific ProductSearch container

  search.ProductSearchID = "UPCSearchWithItems";
  // create a response object for this call
  GetProductsResponseType Response = new GetProductsResponseType();
  // we are now ready to make the call

  try
  {
       Response = svc.GetProducts(Request);

       // if no errors occurred that did not trigger an exception
       // then the result of this call returns a single Product container
       // and an ItemArray, other variations on this call such as using
       // QueryKeywords may return an array of Products

       if (true == Response.AckSpecified && (AckCodeType.Success == Response.Ack || AckCodeType.Warning == Response.Ack))
       {

            // print out the details of this Product
            foreach (CatalogProductType Product in Response.Product)
            {
                 if (null != Product.Title)
                 {
                      Console.WriteLine("The Title of this product is " + Product.Title);
                 }
                 if (null != Product.DetailsURL)
                 {
                      Console.WriteLine("The DetailsURL of this product is " + Product.DetailsURL);
                 }
                 if (null != Product.StockPhotoURL)
                 {
                      Console.WriteLine("The StockPhotoURL of this product is " + Product.StockPhotoURL);
                 }
                 if (true == Product.ItemCountSpecified)
                 {
                      Console.WriteLine("The item count for this product is " + Product.ItemCount.ToString());
                 }
                 if (null != Product.ExternalProductID)
                 {
                      if (true == Product.ExternalProductID.TypeSpecified)
                      {
                           Console.WriteLine("The ExternalProductID for this product is of type " + Product.ExternalProductID.Type.ToString());
                      }
                      if (null != Product.ExternalProductID.Value)
                      {
                           Console.WriteLine("The ExternalProductID value of this product is " + Product.ExternalProductID.Value);
                      }
                 }
                 if (true == Product.ProductReferenceIDSpecified)
                 {
                      Console.WriteLine("The eBay ProductReferenceID of this product is " + Product.ProductReferenceID.ToString());
                 }
            }
       }
  }

 



 

 

版本信息

上面例程基于此特定的API版本及Visual Studio版本:

SOAP API 版本 503
Visual Studio 版本 Original .NET (not 2003 or 2005)

 

答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题