Silverlight 网络服务调用在 Studio 中工作,但从网站运行时失败

标签 silverlight wcf web-services serialization

我们正在构建 Silverlight 应用程序并调用 Silverlight-WCF 服务。从 Visual Studio 运行应用程序时,一切正常。当我们部署到网站并运行应用程序时,每次调用 web 服务时,我们都会收到以下错误(或类似的错误)。

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

根据他的消息,该服务被调用,完全执行,但是当它尝试在 Silverlight 应用程序中反序列化结果时出现问题。关于正在发生的事情以及我们可以做些什么来解决它的任何建议?

<<<<<<<<<<<<<<<<<<<<<<<<<<< 跟进>>>>>>>>>>>>>>>>>>>>>>>>>>>>

这是我们的决议:

在 ServiceReferences.ClientConfig 文件中,我们有以下代码:
<client>
  <endpoint address="http://localhost:5482/WebPortalService.svc"
      binding="customBinding" bindingConfiguration="CustomBinding_WebPortalService"
      contract="WebPortalService.WebPortalService" name="CustomBinding_WebPortalService" />
</client>

注意“本地主机”行。当我们发布时它需要是我们的 web 服务器的地址,但在开发时它需要是 localhost。

任何人对如何自动完成此操作有任何建议,以便我们不必在每次发布之前手动更改此行?

最佳答案

您需要做两件事。

一、提供 clientaccesspolicy.xml and/or crossdomain.xml 网站上的文件。 This MSDN article有详细信息。我还找到了 this blog entry有用。

其次,确保您的服务引用端点指向正确的 URL。对于我的项目,我有不同的构建配置(发布、调试、测试、测试版等)和几个端点。然后我使用 #if 选择合适的端点我的代码中的指令。

例如:

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

关于Silverlight 网络服务调用在 Studio 中工作,但从网站运行时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5107131/

相关文章:

silverlight - Windows Phone 中的 XAML 字符串格式

c# - 读取 XML 数据时已超出最大命名表字符数配额 (16384)

wcf - 允许生成异步操作禁用

java - Web 服务版本控制和服务器端处理

c# - 如何在 Silverlight 中使用 TextRange?

.net - EF4 + MVVM - 在 ViewModel 中公开实体?

wpf - 我们用字形做什么?

c# - 无法在 WCF ServiceModel 客户端配置部分中找到元素

java - 如何通过json获取sendgrid API中的SMTP-ID?

java - Jaxb:将参数传递给@XmlJavaTypeAdapter