question

MohammadAliEchreshavi-1966 avatar image
0 Votes"
MohammadAliEchreshavi-1966 asked WenyanZhang-MSFT commented

How to use Generic Repository for SOAP in Xamarin Form



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 = "")
{
try
{
HttpClient httpClient = CreateHttpClient(uri);
string jsonResult = string.Empty;

var responseMessage = await Policy
.Handle<WebException>(ex =>
{
Debug.WriteLine($"{ex.GetType().Name + " : " + ex.Message}");
return true;
})
.WaitAndRetryAsync
(
5,
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}");
throw;
}
}






dotnet-csharpdotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I‘m not sure if it is what you want, this article demonstrates how to consume an ASMX SOAP service from a Xamarin.Forms application.

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/asmx

0 Votes 0 ·

1 Answer

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered MohammadAliEchreshavi-1966 commented
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thnx for your answer but my problem is impeliment this code with soap requset-response in clinte side no server side

0 Votes 0 ·