Silverlight 2 + WCF Service Deployment Issue
While deploying a very simple Silverlight application using a Silverlight enabled WCF service, I ran into this little problem:
On my development machine hosting the app using the normal VS host (By running the app using F5) everything works perfectly (Creating a random port number for the app and service)
If I now deploy this app and service to my production machine, the Silverlight app works but it can’t access the WCF service!!!
Things I double checked:
- Make sure the Silverlight application runs. If not, add the MIME types
- Make sure the service is working
My service is called MISService.svc so to check that it worked, I opened it in IE (http://localhost/MISService.svc)
If both your Silverlight application and service work, it might indicate a cross domain boundaries problem, here is a document how to fix it.
If it still doesn’t work, try the following:
The problem is that in the ServiceReference.ClientConfig file (Created by using VS Add Service Reference), the endpoint is setup with a specific port number (1192 in the following example)
<client>
<endpoint address="http://localhost:1192/MISViewerWeb/MISService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MISService"
contract="MISViewer.MISServiceReference.MISService" name="BasicHttpBinding_MISService" />
</client>
Now if I create the client, I get a UnexpectedHttpResponseCode exception. Here is the code that creates the service client
MISServiceClient client = new MISServiceClient()
To make it work again, I changed this to the following
Uri address = new Uri(Application.Current.Host.Source, "../MISService.svc");
MISServiceReference.
MISServiceClient client =
new MISServiceReference.
MISServiceClient(
"BasicHttpBinding_MISService", address.AbsoluteUri);
This bypasses the ServiceReference.ClientConfig file!
If you found this useful, please 