Yesterday, while developing a demo app that uses Prism-v2, WCF services, ASP.NET web application and interaction with WebBrowser controls ,  I run into a little problem trying to consume the service from a module.  I thought could be useful posting about it to save someone a little time.

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.

image

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.

image

 

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.
 

kick it on DotNetKicks.com

2 Responses to “How-to: Consume WCF services from Composite Application Guidance for WPF and Silverlight(Prism-v2) Modules”

  1. Damian Schenkelman’s Blog » Blog Archive » WebBrowser control Quickstart for the Composite Application Guidance for WPF and Silverlight (Prism-v2) Says:

    [...] can also check out some tips about using WCF services in Prism in this post by [...]

  2. Stuart Says:

    Hi Matias

    Thanks for helping me out with a problem I was having consuming a web service within a Silverlight module!

    Yours

    Stu

Leave a Reply