Vince Plaza's Blog

...Microsoft .NET programming ideas and samples

October 16th, 2009

...now browsing by day

 

“Could not find default endpoint” error with Silverlight, WCF, and MVVM

Friday, October 16th, 2009

I have done this a couple of times, and so thought I would log it so that I remember next time. When I set up a Silverlight project using the MVVM pattern, I prefer to make separate projects for the View and ViewModel sections. I then create a service reference to my data service (WCF) in the ViewModels project. If you have tried this, you may have received a “Cannot find ‘ServiceReferences.ClientConfig’ in the .xap application package.” error message the first time you run the solution. This is caused by the Views project not containing the ServiceReferences.ClientConfig file created in the ViewModels project. No problem, just drag a copy from the ViewModels project into the Views project and you are set to go.

Where I get into trouble is when I reconfigure the WCF service or reference and forget to update the client config file I dragged into the Views project. The error message that gets generated is similar to:

Could not find default endpoint element that references contract ‘ServiceReference.Service’ 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.

Well, I was much happier with the error message telling me the file was missing. With this new message, I end up opening the client config file in the ViewModels project like 6 times looking for a typo, but of course it was auto generated while making the service reference, and so is fine. What I need to do is to replace the ServiceReferences.ClientConfig file in the Views project, and then run the application again. Problem solved.