The Silverlight webservice call works in Studio, but does not execute when launched from the website

We are creating a Silverlight application and have calls to the Silverlight-WCF service. When I run the application from Visual Studio, everything works fine. When we deploy the site and launch the application, we get the following error (or the same as it) with every call to 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 his message, the call is called, it is fully executed, but when he tries to deserialize the results in the Silverlight application, something will go wrong. Any suggestions on what is happening and what can we do to fix it?

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<FOLLOW UP β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’ β†’>

That 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> 

Note the line "localhost". It should be our web server address when published, but it must be local during development.

Does anyone have any suggestions on how to do this automatically, so we don’t need to manually change this line before publishing?

+4
source share
2 answers

There are two things 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 post to be helpful.

Second, make sure that the service link endpoints point to the correct URL. For my projects, I have different layout configurations (Release, Debug, Test, Beta, etc.) and several endpoints. Then I select the appropriate endpoint using the #if directives in my code.

For instance:

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

This usually happens when the WCF service is deployed in a different domain in relation to the location of the application. If this is a temporary situation in which the tboth service and application in the same domain will be solved. If this is not possible, it is possible to create a proxy for the remote service in the application.

0
source

Source: https://habr.com/ru/post/1341159/


All Articles