Skip to main content

Posts

Showing posts with the label WCF

Proper initialize/dispose with WCF and MEF

Initialization and disposing of services in a WCF application is a bit of a hassle to control when running on an IIS instance, since the application starts and stops every now and then based on server requests. It doesnt make it easier when using an IOC, as in our case MEF. To have total control of the startup and shutdown events we began with adding a service factory to all our WCF services. <%@ ServiceHost Language="C#" Debug="true" Service="WcfService" Factory="CustomServiceHostFactory" %> When ever the application gets woke up by a request to any of the services, the service factory will be used to instantiate the service. This means we can add any logic to these methods to have full control of the WCF application initialization. Here is what a service factory class could look like. (Composition is a static class containing a reference to the MEF container) public class CustomServiceHostFactory : ServiceHostFactory { priva...

Connecting to SOAP service with certificate authentication

I have rarely worked with certificate based authentication, so when I got this neat little SOAP service with certificate authentication in my hands I gladly accepted the challenge. All I got was the URL to the service with a certificate and the password. I also got an example written in PHP: $client = new SoapClient("https://url.to.service/", array(         'local_cert' => 'client_certificate.pem', 'passphrase' => 'PASSPHRASE',         'cache_wsdl' => WSDL_CACHE_NONE )); This of course looks very easy, but we all know that it's not really that easy if I want to use .NET and WCF. First of all the PEM-certificate cannot natively be used in .NET. Second of all I don't have the WSDL for the service. Here are the steps I had to go through to be able to successfully connect to the SOAP service. Convert the certificate The certificate I received was a PEM certificate which included both the private and public key. .NET ...