How-to: Consume WCF services from Composite Application Guidance for WPF and Silverlight(Prism-v2) Modules
June 20th, 2009
The Problem
I had a WCF service in place. It was working fine with a ASP.NET web app, but when I tried to cunsume it from a Prism-v2 module I got the following exception:
‘System.InvalidOperationException: Could not find default endpoint element that references contract ‘CustomerService.ICustomerService’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I was using the app.config that was generated by the WCF “add service reference” wizard. I checked it’s content but everything was fine.
The solution
Move the app.confing to the Shell project!
In prism modules are loaded dynamically, so they all run in the Shell project context. WCF was not finding my app.config because it was not in the right place.
This will do for simple applications, but most general application already have an app.config with settings. On the other hand, modules should be completely decoupled from the shell. A good way to resolve these issues is to set WCF configuration within the module programatically.
I hope this is useful when consuming WCF Services from Prism Modules.