As all of us know if something went wrong in the Silverlight application that is consuming WCF, how much painful it is to investigate the problem. Debugging only help to certain level, as it do not always give the exact error message. It sucks and it eats considerable amount of time to know the problem and all that we end up in identifying nothing. If we know some smart tips in WCF +Silverlight that will help us in reducing some time and identifying the issues.
Debug Silverlight Application
Method1. If we directly place a break point it might not get hit. The problem might be Silverlight Debugging is not enabled In order to Debug Silverlight application Go to Solution Properties , right click and select property pages -> Navigate to Start Options - >Debuggers -> select Silverlight checkbox
Method2. Using Visual Studio you can attach to an instance of your browser that has a Silverlight application running from the server (IIS). This is very useful especially as unexpected problems can occur once you deploy and run your application on the server. These problems you may not see when you just run locally on your box.
To accomplish this open up Visual Studio.
From the menu select Tools->Attach to process (Ctrl+Alt+P). This will bring up the following dialog.
We need to identify instance of the browser to attach the process, Check Type =Silverlight 86 . Click on the attach button and now we can debug the application.
The remote server returned an error: Not Found
Most common Exception in WCF with Silverlight is Message="The remote server returned an error: NotFound." And we are sure that something went wrong in the service no clue where exactly the exception happened. WCF never gives exact error. The only error it gives is remote server returned an error. In this case fiddler helps in identifying why the issue is. If we can identify the problem and why it is caused then it’s easy to find the solution. Make sure that you have any debugging tools like fiddler or web development helper , HTTP Snippet tools to debug and know what exactly happening . These tools will help us to know what exactly the error is.
Some times you get CommunicationException as follows . System.ServiceModel.CommunicationException was unhandled by user code.If you get this error, then the WCF service is trying to tell you that something went wrong, but the full error information is not making it back to Silverlight. To fix this problem, add the following line to the MainPage constructor in your Silverlight application. This switches over to the new ClientHttp stack will fix the problem.
This line of code can be removed once done with the debugging.
You need to change this line in your WCF service Web.config file, and change this value to true as follows .
This should give you much more information in your Silverlight client about what's going wrong.
- You cannot debug Silverlight application and the applications hosting Silverlight together
- Use Expression Blend to Edit the XAML File, Visual Studio supports integration with Expression Blend.