We are building a Silverlight application and have calls to a Silverlight-WCF service. When running the application from Visual Studio everything works perfectly. When we deploy to the website and run the application we get the following error (or one much like it) every time we call the web-service.
Message: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at SSS.MVVMCore.Silverlight.WebPortalService.GetThemeIdCompletedEventArgs.get_Result()
at SSS.MVVMCore.Silverlight.ViewModels.StandardBaseFrameViewModel.<.ctor>b__0(Object s, GetThemeIdCompletedEventArgs ea)
at SSS.MVVMCore.Silverlight.WebPortalService.WebPortalServiceClient.OnGetThemeIdCompleted(Object state)
Line: 1
Char: 1
Code: 0
URI: http://ssswebportal.com/login.aspx?p=d53ae99b-06a0-4ba7-81ed-4556adc532b2
Based on he message, the service is called, executes completely, but when it tries to deserialize the results back in the Silverlight app something goes wrong. Any suggestions as to what is happening and what we can do to fix it?
<<<<<<<<<<<<<<<<<<<<<<<<<<<< FOLLOW UP >>>>>>>>>>>>>>>>>>>>>>>>>>>>
This was our resolution:
In the ServiceReferences.ClientConfig file, we had the following code:
<client>
<endpoint address="http://localhost:5482/WebPortalService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_WebPortalService"
contract="WebPortalService.WebPortalService" name="CustomBinding_WebPortalService" />
</client>
Notice the ‘localhost’ line. It needs to be our web server’s address when we publish but it needs to be localhost when developing.
Anyone have any suggestions on how to accomplish this automatically, so that we do not have to manually change this line before every publish?
There are two things that you need to do.
First, provide
clientaccesspolicy.xmland/orcrossdomain.xmlfiles on the website. This MSDN article has details. I also found this blog entry to be useful.Second, ensure that your service reference endpoints are pointing to the right URL. For my projects, I have different build configurations (Release, Debug, Test, Beta, etc.) and several endpoints. I then select the appropriate endpoint using
#ifdirectives in my code.For example: