Skip to main content
Published: February 03 2006, 3:30:00 PMUpdated: July 22 2022, 11:25:29 AM

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:

  • API errors using TriggerErrorCodes
  • .NET / SDK exception using TriggerExceptions
  • HTTP errors using TriggerHttpStatusCodes

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;
    }
}
 

Notes:
  • You must retry only if they are infrastructure errors, i.e. errors caused on the eBay server side and not because of an error in your application. You must try no more than 2 times.  If the problem persists, you must check the Site Status or report the issue via a Support Request.  
  • Do not implement call retry for Application errors.  These are caused by problems in the application logic or incorrect data in the request. Retries will not help resolve these issues. You must check the Error result set returned by the API call and set valid input arguments before you retry. An easy way to figure out what is causing the error is to open the log and inspect the call request and response.
 

Additional Resources

 



Attachments
How well did this answer your question?
Answers others found helpful