From time to time I’ll hear from somebody who is trying to use a WCF Workflow Service with Silverlight as the client and they are getting this exception.
System.ServiceModel.CommunicationException was unhandled by user code Message=An error occurred while trying to make a request to URI http://localhost:49238/SecurityDoorService.xamlx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.
There I was at Tech-Ed 2011 about to do my talk on Workflow with State Machines. I had written a demo application (Silverlight / State Machine Workflow Service) and in the final minutes before the presentation I was testing things one last time when I ran into this problem. Beads of sweat formed on my forehead as I frantically tried to get my application working. Nothing is worse for a presenter than to have your demo blow up at a conference.
Over and over again I ran it. I checked the config files, I checked the web server… everything looked right and then I noticed something in the address bar of IE.
My Silverlight app was running in the HTML file loaded from a file:// URI and not over http. No wonder that Silverlight saw the call to a web service at http://localhost as a cross domain call.
The solution is very simple. If you look at Solution Explorer you will see that when this happened I had my Silverlight project set as the startup project.
All I had to do was set the SecurityDoor.Web project as the startup project and everything worked just fine.
This problem is so common that since then Silverlight has added a dialog that warns you when you are about to do this.
I’m not exactly sure when this was added – I know I had not seen it until the last week or two when I started getting more email about this subject. Maybe it was there previously and I had switched it off – I don’t know.
At any rate, make sure you set the correct startup project and that will eliminate one source of this issue.
Happy Coding! Ron Jacobs http://www.ronjacobs.com @ronljacobs