Visual Studio 2010 Silverlight/WCF Port Number problem

I’ve been developing a Silverlight 3 App with a data supplied through WCF service in VS2010. I set the app up using the Silverlight template in VS2010 at selected ‘Web Site’ as the Project Type, then added a Silverlight enabled WCF service to the solution’s web site project. So the Silverlight App & the WCF service are running from the same web site, which means I shouldn’t have any cross domain issues.

Everything has been fine for a week or so and my app has been growing in complexity as I try out more and more Silverlight 3 functionality. Today however, it all went horribly wrong and my WCF call failed with the following error …

System.ServiceModel.CommunicationException was unhandled by user code

The problem boils down to Visual Studio had arbitrarily decided to start using a different port number. The client was still using the old port number in the endpoint address and never the twain shall meet. Updating the Service reference doesn’t fix-up the endpoint address although deleting the service reference and recreating it, though a bit of a pain, does. The best way to fix the problem is to change the endpoint address that the client uses manually. There’s a file in the Silverlight Application called ‘ServiceReferences.ClientConfig’ …

… Just load it into the VS text editor and change the port number to the same one shown in the URL shown in the browser address bar when your Silverlight app fires up.

As a footnote there doesn’t seem to be a way to specify the port number that the development web server uses, I can’t find a Web tab in my web project properties – hopefully it will be added in the final version of VS2010.

Like this:

LikeLoading...

Related

You can specify a static port for the development server in VS2010. The option has moved to the property page for the web server. One of the properties is called “Use Dynamic Ports” which can be set to false and a Port Number can be specified.