Creating Service Reference: Failed to generate code for the service reference

When accessing a remote SQL Server database from a Windows Phone 7 device, the preferred way to interact with the database is through the implementation of a WCF Service. This is the scenario that we will work with. Say we have a SQL Server database sitting on a remote server. On the remote server, we also have IIS installed and our WCF Service application up and running that provides access to the database via LINQ to SQL classes, and the client device that communicates with the database via the WCF Service is a Windows Phone 7 Device.

If we change the structure of the database and update the LINQ to SQL schema, we need to update our service references within the client project. However, when we update the service reference we get the error ‘Failed to generate service reference’.

The first thing to check is that our service works using the VS2010 WCF Test Client. If the WCF Service fails within the test client, we need to fix the relevent issues that prevent the service from successfully running. Once we have the service running successfully with the VS2010 WCF Test Client, we then delete the service references and client config files from within the Windows Phone 7 application. After we have done this, we close the project down and edit the Windows Phone 7 project file in Notepad and remove any remaining references to the service references. We also delete the project user properties file. When we are done deleting everything, we save the project file and reopen the Windows Phone 7 solution and re-add the service references. And now everything works fine.