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.
June 23rd, 2009 at 5:24 am
[...] can also check out some tips about using WCF services in Prism in this post by [...]
January 22nd, 2010 at 8:07 am
Hi Matias
Thanks for helping me out with a problem I was having consuming a web service within a Silverlight module!
Yours
Stu