Created
June 8, 2020 10:38
-
-
Save NimzyMaina/418329e468aa18b45750ff3b1608acd2 to your computer and use it in GitHub Desktop.
Temp Convert Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ServiceModel; | |
using System.Threading.Tasks; | |
using System.Xml; | |
using Microsoft.Extensions.Options; | |
using TempConvert.Models; | |
using TempConvert.Interfaces; | |
namespace TempConvert.Repositories | |
{ | |
public class TempConvertRepository : ITempConvertRepository | |
{ | |
private readonly ITempConvertChannel _proxy; | |
public TempConvertRepository(IOptions<ClientConfig> config) | |
{ | |
var cfg = config.Value; | |
/* | |
* Create & Configure Client | |
*/ | |
BasicHttpBinding binding = new BasicHttpBinding | |
{ | |
SendTimeout = TimeSpan.FromSeconds(cfg.Timeout), | |
MaxBufferSize = int.MaxValue, | |
MaxReceivedMessageSize = int.MaxValue, | |
AllowCookies = true, | |
ReaderQuotas = XmlDictionaryReaderQuotas.Max | |
}; | |
binding.Security.Mode = BasicHttpSecurityMode.Transport; | |
EndpointAddress address = new EndpointAddress(cfg.Url); | |
ChannelFactory<ITempConvertChannel> factory = new ChannelFactory<ITempConvertChannel>(binding, address); | |
this._proxy = factory.CreateChannel(); | |
} | |
public async Task<string> FahrenheitToCelsiusAsync(string fahrenheit) | |
{ | |
return await _proxy.FahrenheitToCelsiusAsync(fahrenheit); | |
} | |
public async Task<string> CelsiusToFahrenheitAsync(string celsius) | |
{ | |
return await _proxy.CelsiusToFahrenheitAsync(celsius); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment