Monthly Archives: September 2011

When making service calls from a library…

Just in case you’re working in a C# class library project and need to make an HTTPS web service call and the project in which you’re working isn’t the root project of the solution, then you can either go through the brain damage of editing the app.config of the root project or you can explicitly set the binding and address of the service call in code, which is faster and easier than it seems:

using System.ServiceModel;
 
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
string serviceUrl = "https://www.somedomain.com/service.svc";
EndpointAddress address = new EndpointAddress(serviceUrl);
MyService.MyServiceSoapClient _myService = new MyService.MyServiceSoapClient(binding, address);
 
string result = _myService.doUsefulWork(param1, param2, param3, paramEtc);