Silverlight cant communicate with WCF in certain config situations - solution
Sample Error piece: Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
This problem manifests for me in the following situation.
- Silverlight App hosted in a ASPX site
- The Silverlight app is a data-consumer and requires data via a WCF service also hosted in the ASPX Page
Everything works fantastic when you run it via F5 in VS. Once published to IIS it stops communicating with WCF.
Two problems cause this:
- The Silverlight app is defaulting to the https://localhost:25775/servicename.svc
- Get rid of the port number as it thinks your trying to communicate across domain https://localhost/servicename.svc
- Note this wont work via VS when you change it
- If you have that fixed but the silverlight app reverts to being unable to communicate with the WCF service again when called remotely you need to do the following(works for me anyway):
- Publish the Website with all pieces, SIlverlight, WCF etc to your IIS publish location
- Go back tot he Silverlight App and open your web reference to the service in VS
- Change it to point at the newly deployed web service location
- Change LocalHost to your server name or what ever your setup is. ie https://MyServer/servicename.svc
- Press OK in the configure service and build the silverlight app
- Copy the newly compiled .xap file from the clientbin folder
- Overwrite the deployed .xap file in the location where you published your service
- Open up the silverlight app\Website from the published location
This should now communicate fine under the https://MyServer/servicename.svc but will not under https://localhost/servicename.svc as it will look for the servername and not localhost
Ideally it really should figure this out for itself in a perfect world ;-)
Really hope this helps!
The Actual errors
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Timestamp: Mon, 29 Nov 2010 21:43:41 UTC
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 MyService.GetMyJobsCompletedEventArgs.get_Result()
at MyService.MainPage.t_GetMyJobsCompleted(Object sender, GetMyJobsCompletedEventArgs e)
at MyService.MyClient.OnGetMyJobsCompleted(Object state)
An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
[ExceptionOccurred]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See https://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50917.0&File=System.dll&Key=Async_ExceptionOccurred