Home
Find the answer to your question
How can I retry a call with the .NET SDK?
Summary
The SDKs makes it very simple to implement retry for a call. The APICall class has a property CallRetry. All that you need to do is to instantiate an object of the CallRetry class and set the number of retries, the errors for which you want to retry and the interval at which you want to retry. Its as easy as that!
Detailed Description
The .NET SDK lets you retry on any of following errors:
Here is a .NET SDK example written C# to implement retry for GeteBayOfficialTime:
using System;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Util;
using eBay.Service.Core.Soap;
namespace SDKSample
{
public void RetryDemo()
{
GeteBayOfficialTimeCall apicall = new GeteBayOfficialTimeCall(GetContext());
// Instantiate the CallRetry object;
apicall.CallRetry = new CallRetry();
//Set the time interval in milliseconds after which you want to retry on failure
apicall.CallRetry.DelayTime = 5000;
// Set the maximum number of retries
apicall.CallRetry.MaximumRetries = 3;
// Set the API error codes for which you want to retry
apicall.CallRetry.TriggerErrorCodes = new StringCollection();
apicall.CallRetry.TriggerErrorCodes.Add("10007"); // Internal error to the application ... general error
apicall.CallRetry.TriggerErrorCodes.Add("2"); // unsupported verb error
apicall.CallRetry.TriggerErrorCodes.Add("251"); // eBay Structured Exception ... general error
// Set the Exception types on which to retry
apicall.CallRetry.TriggerExceptions = new TypeCollection();
apicall.CallRetry.TriggerExceptions.Add(typeof(System.Net.ProtocolViolationException));
// Set the HTTP error codes on which to retry
apicall.CallRetry.TriggerHttpStatusCodes = new Int32Collection();
apicall.CallRetry.TriggerHttpStatusCodes.Add(404);
apicall.CallRetry.TriggerHttpStatusCodes.Add(502);
apicall.CallRetry.TriggerHttpStatusCodes.Add(500);
try
{
DateTime eBayTime = apicall.GeteBayOfficialTime();
}
catch (Exception ex)
{
// Handle the exception
}
}
public ApiContext GetContext()
{
context = new ApiContext();
//set the your credentials
context.ApiCredential.eBayToken = "token";
context.ApiCredential.ApiAccount.Application = "AppID";
context.ApiCredential.ApiAccount.Developer = "DevID";
context.ApiCredential.ApiAccount.Certificate = "CertID";
context.SoapApiServerUrl = ""url";
//set the version
context.Version = "791";
//set the logging
string logFile = "LogFile.txt";
context.ApiLogManager = new ApiLogManager();
context.ApiLogManager.ApiLoggerList.Add(new FileLogger(logFile, true, true, true));
context.ApiLogManager.EnableLogging = true;
return context;
}
}