Showing posts with label WCF Client. Show all posts
Showing posts with label WCF Client. Show all posts

Thursday, April 26, 2012

External config for CRM Online wsdl based proxy

The sample which comes with CRM SDK to connects to CRM Online services uses an extension method and a partial class to attach the appropriate federation tokens for authenticating the calls against live services. 
The extension method is given for any class which derives from ClientBase. The DiscoveryServiceClient and OrganizationServiceClient are the proxy classes which derive from ClientBase and ClientBase respectively. The limitation of deriving from ClientBase is that the WCF Configuration has to be read from app.config or web.config files. 
Sometimes there are limitations where you want to read these configurations from an external file e.g. if you are shipping an add-in to outlook you definitely don't want to ship outlook.exe.config file. 
.NET 4.5 adds the capabilities for reading the configuration from external file but if you are developing against .NET 4.0 or earlier versions you face an issue and the only way out is to use a Custom Channel Factory as described on http://www.mssoftwareconsulting.com/msswc/blog/post/Override-WCF-Client-Settings-From-Custom-Config-File.aspx 

And instantiate the Channel using the Custom Channel Factory. However this class doesn't have a method to configure federation and attach appropriate tokens to the channel to call the CRM Online service successfully. 
The attached sample provides an additional method in this class which can be used to attach proper tokens to the channel. 


The sample can be downloaded from here


Happy coding!!!


¬Abhishek

Friday, May 1, 2009

Consuming WCF services on SSL

Okay so its been ages since i posted something here and just now i struggled with a problem which i struggled with so many times during the past 2-3 months. So i decided to document the solution here as it might help someone else or me to fix this sometime in future :).
So I am working with a WCF service exposed over IIS with SSL binding.
I setup a WCF client for consuming this service and everything was supposed to work out of the box. However there are hiccups which one faces. And the worse is that you start getting security exceptions which give hardly any information about what the problem could be. All i was able to understand was that there's a problem establishing a secure connection over TLS/SSL.
So here are a few troubleshooting steps
1) If its the development/test environment and you are using a SSL certificate issued by an internal authority then ensure that you have the root certificate authority installed in your trusted authoritites store. (In a typical development environment certificates are stored on a shared folder and all the people in team use different copies of certificates from this shared folder. Sometimes certificate authority certificate has versions and the one you trust is a different version itself). So the safest option is to hit the service from IE. Check the certificate , export the root certificate authority in a .CER file and install it in your local machine store. Byu default the wizard will install it in your personal store though its a good idea to copy it to local machine store because you might be using some other account to consume this service.

2) Another problem one faces quite often in the development environment is that the SSL certificate is issued to a specific machine while multiple developers use the same certificate to work in parallel. In such a case the consumer of this service might face an exception as the name of the machine to which the certificate has been issued is different then the name of the machine it is being presented by. To skip this check we can configure the ServicePointManager component in .NET to skip the name verification process. To do this add the following section to your config file for the WCF client....







I'll update this post as i face more issues with SSL......

~Abhishek

PS :- I am working on a reusable Performance counter application block which i might publish on this blog in some time.