EBay .Net SDK Api 实践

 

 

1.请求流程介绍

 

提供SOA地址:https://api.ebay.com/wsapi

 

WSDL生成的代码在WebService.cs文件当中。

 

ApiCall封装了所有的RPC,其核心实现在SendRequest里面,其中有两个事件,请求之前,与请求之后

CustomSecurityHeaderType封装了用户认证信息

SoapHttpClientProtocolEx继承SoapHttpClientProtocol,加上了SoapRequest,SoapResponse属性。用来生成请求和响应的XML报文。

 

使用ApiLogManager进行日志记录

 

2.实践

 

  • 非string字段,使用 "属性Specified" = true

如:

pagination.PageNumberSpecified = true;

 

  • 捕获ApiException,遍历Errors来细化错误

如:在ReviseInventoryStatus时,一次调整四个SKU就需要遍历错误结果

  1. catch (ApiException apiEx)
  2. {
  3.     var str = string.Empty;
  4.     foreach (ErrorType error in apiEx.Errors)
  5.     {
  6.         if (error.SeverityCode == SeverityCodeType.Error)
  7.         {
  8.             foreach (ErrorParameterType ePara in error.ErrorParameters)
  9.             {
  10.                 str += ePara.ParamID + ":" + ePara.Value + " ";
  11.                 if (ePara.ParamID == "SKU")
  12.                 {
  13.                     returns.Remove(returns.First(zw => zw.SKU == ePara.Value));
  14.                 }
  15.             }
  16.             str += error.LongMessage + Environment.NewLine;
  17.         }
  18.     }
  19.  
  20.     //有错误的
  21.     NotifyAndLog(string.Format(ResPriceCaptureAndRevise.Wrong_PriceRevised, "", str),
  22.         LogLevel.Error, accPriceInfo.SellerAccount);
  23. }

 

  • 使用ApiResponse.Ack

如果使用Ack来判断,可能某些有数据返回的时候,状态不是Success,而是Warning

  1. if (apicall.ApiResponse.Ack == AckCodeType.Success || apicall.ApiResponse.Ack == AckCodeType.Warning)
  2. {
  3.    //
  4. }

 

  • 分页

Pagination

  1. PaginationType pager = new PaginationType();
  2. pager.EntriesPerPage = 100;
  3. pager.EntriesPerPageSpecified = true;
  4.  
  5. for (int page = 1; page <= totalPage; page++)
  6. {
  7.     pager.PageNumber = page;
  8.     pager.PageNumberSpecified = true;
  9.  
  10.     if (apicall.ApiResponse.Ack == AckCodeType.Success || apicall.ApiResponse.Ack == AckCodeType.Warning)
  11.     {
  12.         // 保存数据
  13.         totalNum = (apicall.ApiResponse.PaginationResult == null ? 0 : apicall.ApiResponse.PaginationResult.TotalNumberOfEntries);
  14.         totalPage = (apicall.ApiResponse.PaginationResult == null ? 0 : apicall.ApiResponse.PaginationResult.TotalNumberOfPages);
  15.      }
  16. }

在ApiResponse. PaginationResult的TotalNumberOfEntries和TotalNumberOfPages获取总数和分页数。

posted @ 2015-09-23 14:55  _DN  阅读(562)  评论(0编辑  收藏  举报