ErocM
ErocM

Reputation: 4662

Silverlight webservice call works in Studio but fails when run from website

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?

Upvotes: 4

Views: 2559

Answers (2)

Jeff Yates
Jeff Yates

Reputation: 62377

There are two things that you need to do.

First, provide clientaccesspolicy.xml and/or crossdomain.xml files 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 #if directives in my code.

For example:

    soapClient =
#if DEBUG
        new MySoapClient("DebugService");
#elif TESTRELEASE
        new MySoapClient("TestService");
#elif BETA
        new MySoapClient("BetaService");
#else
        new MySoapClient("ReleaseService");
#endif

Upvotes: 2

Felice Pollano
Felice Pollano

Reputation: 33252

This usually happen when the WCF service is deployed in a different domain in respect to the application location. If this is a temporary situation having tboth service and application on the same domain will solve. If it is not possible create a proxy for the remote service on the application could work.

Upvotes: 0

Related Questions