How to use Generic Repository for SOAP in Xamarin Form

Mohammad Ali Echreshavi 61 Reputation points

hi,I used Generic Repository in my sample project in Xamrin form to get data from api. so my question is how can I make the following code Repository for soap webervice to become generic. so that the If you know of an example or a blog post please point me to the right direction

it is my Sample code:

public interface IGenericRepository

Task<T> GetAsync<T>(string uri, string authToken = "");


and impeliment interface:

public class GenericRepository: IGenericRepository

public async Task<T> GetAsync<T>(string uri, string authToken = "")
HttpClient httpClient = CreateHttpClient(uri);
string jsonResult = string.Empty;

        var responseMessage = await Policy
            .Handle<WebException>(ex =>
                Debug.WriteLine($"{ex.GetType().Name + " : " + ex.Message}");
                return true;
                retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
            .ExecuteAsync(async () => await httpClient.GetAsync(uri));

        if (responseMessage.IsSuccessStatusCode)
            jsonResult =
                await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
            var json = JsonConvert.DeserializeObject<T>(jsonResult);
            return json;

        if (responseMessage.StatusCode == HttpStatusCode.Forbidden ||
            responseMessage.StatusCode == HttpStatusCode.Unauthorized)
            throw new ServiceAuthenticationException(jsonResult);

        throw new HttpRequestExceptionEx(responseMessage.StatusCode, jsonResult);

    catch (Exception e)
        Debug.WriteLine($"{ e.GetType().Name + " : " + e.Message}");
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,818 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,006 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Duane Arnold 3,211 Reputation points