pmorelli92/SoapHttpClient

No authorization options?

Closed this issue · 3 comments

Hey, im trying to use your package but there is no way to use any authorization option i am right? I have a SOAP Service that requires Basic Authorization for example. Thanks!

Hey @maxwidergy you can customise the underlying HttpClientFactory to add any headers you want: https://github.com/pmorelli92/SoapHttpClient/blob/master/Source/SoapHttpClient/SoapClient.cs#L27

thanks for the answer! so i should fork the repo and make the changes my self right?

No need, you can create your own HttpClientFactory like:

    public class AuthorizationHttpClientFactory : IHttpClientFactory
    {
        public HttpClient CreateClient(string name)
        {
            var client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer x.x.x");
            return client;
        }
    }

And then do:

var factory = new AuthorizationHttpClientFactory();
var client = new SoapClient(factory);

There is an example here https://github.com/pmorelli92/SoapHttpClient/blob/master/Tests/SoapHttpClient.Tests/SoapClientTests.cs#L109-L110