标签:
?
?
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就需要遍历错误结果
catch (ApiException
apiEx)
{
????var str = string.Empty;
????foreach (ErrorType error in apiEx.Errors)
????{
????????if (error.SeverityCode == SeverityCodeType.Error)
????????{
????????????foreach (ErrorParameterType ePara in error.ErrorParameters)
????????????{
????????????????str += ePara.ParamID + ":" + ePara.Value + "
";
????????????????if (ePara.ParamID == "SKU")
????????????????{
????????????????????returns.Remove(returns.First(zw => zw.SKU == ePara.Value));
????????????????}
????????????}
????????????str += error.LongMessage + Environment.NewLine;
????????}
????}
?
????//有错误的
????NotifyAndLog(string.Format(ResPriceCaptureAndRevise.Wrong_PriceRevised, "", str),
????????LogLevel.Error, accPriceInfo.SellerAccount);
}
?
如果使用Ack来判断,可能某些有数据返回的时候,状态不是Success,而是Warning
if (apicall.ApiResponse.Ack == AckCodeType.Success || apicall.ApiResponse.Ack == AckCodeType.Warning)
{
???//
}
?
Pagination
PaginationType
pager = new PaginationType();
pager.EntriesPerPage = 100;
pager.EntriesPerPageSpecified = true;
?
for (int page = 1; page <= totalPage; page++)
{
????pager.PageNumber = page;
????pager.PageNumberSpecified = true;
?
????if (apicall.ApiResponse.Ack == AckCodeType.Success || apicall.ApiResponse.Ack == AckCodeType.Warning)
????{
????????// 保存数据
????????totalNum = (apicall.ApiResponse.PaginationResult == null ? 0 : apicall.ApiResponse.PaginationResult.TotalNumberOfEntries);
????????totalPage = (apicall.ApiResponse.PaginationResult == null ? 0 : apicall.ApiResponse.PaginationResult.TotalNumberOfPages);
?????}
}
在ApiResponse. PaginationResult的TotalNumberOfEntries和TotalNumberOfPages获取总数和分页数。
EBay .Net SDK Api 实践
标签:
原文地址:http://www.cnblogs.com/pengzhen/p/4832276.html