Let's suppose I have the following methods:
public string GetSchedules(string request) { using (var soapClient = new ServiceReference1.CustomDataTimetableToolKitServicesSoapClient(EndpointConfiguratioName, Endpoint)) { return soapClient.GetSchedules(AuthenticationInfo, request); } } public string GetCountryList(string request) { using (var soapClient = new ServiceReference1.CustomDataTimetableToolKitServicesSoapClient(EndpointConfiguratioName, Endpoint)) { return soapClient.GetCountryList(AuthenticationInfo, request); } } public string GetCarriers(string request) { using (var soapClient = new ServiceReference1.CustomDataTimetableToolKitServicesSoapClient(EndpointConfiguratioName, Endpoint)) { return soapClient.GetCarriers(AuthenticationInfo, request); } } As you can see the only different thing is the name of the method invoked. How could I refactor these methods to apply "using" statement only once and avoid code duplication?
usingstatement with WCF clients - MSDN