EBay .Net SDK Api 实践

 

 

1.请求流程介绍

 

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

 

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

 

ApiCall封装了全部的RPC,其核心实如今SendRequest里面,其中有两个事件,请求以前,与请求以后 3d

CustomSecurityHeaderType封装了用户认证信息 日志

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

 

使用ApiLogManager进行日志记录 blog

 

2.实践

 

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

如: 继承

pagination.PageNumberSpecified = true; 事件

 

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

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

  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 get

  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获取总数和分页数。

相关文章
相关标签/搜索