silverlight - 动态加载的 xap 中的 WCF 服务调用失败

标签 silverlight mef dynamically-loaded-xap

我有一个容器/主 Silverlight 应用程序。此容器动态下载 xap 并调用下载的 xap 中的特定用户控件。
其中一些用户控件调用托管在服务器上的 WCF 服务。

当下载的 xap 中的用户控件调用 WCF 服务时,会出现以下错误:

System.InvalidOperationException was unhandled by user code
Message=Cannot find 'ServiceReferences.ClientConfig' in the .xap application 
package. This file is used to configure client proxies for web services, and 
allows the application to locate the services it needs. Either include this 
file in the application package, or modify your code to use a client proxy
constructor that specifies the service address and binding explicitly. Please
see inner exception for details.
StackTrace:
   at System.ServiceModel.Configuration.ServiceModelSectionGroup.
       GetSectionGroup()
   at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Current()
   at System.ServiceModel.Description.ConfigLoader.LookupChannel(
       String configurationName, String contractName, Boolean wildcard)
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(
       ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(
       String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(
       String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(
       String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(
       EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1..ctor()
   at LoadableSilverlightApplication.MyServiceReference.MyServiceClient..ctor()
   at LoadableSilverlightApplication.Views.MyLoadablePage.textBlock2_Loaded(
       Object sender, RoutedEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(
       Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(
       IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, 
       Int32 actualArgsTypeIndex, String eventName)
  InnerException: System.Xml.XmlException
      Message=Cannot find file 'ServiceReferences.ClientConfig' in the
          application xap package.
      LineNumber=0
      LinePosition=0
      StackTrace:
           at System.Xml.XmlXapResolver.GetEntity(
               Uri absoluteUri, String role, Type ofObjectToReturn)
           at System.Xml.XmlReaderSettings.CreateReader(
               String inputUri, XmlParserContext inputContext)
           at System.Xml.XmlReader.Create(
               String inputUri, XmlReaderSettings settings, 
               XmlParserContext inputContext)
           at System.ServiceModel.Configuration.ServiceModelSectionGroup.
               GetSectionGroup()
      InnerException:
          ...

异常告诉我 ServiceReferences.ClientConfig不知何故不可见......即使它打包在下载的xap中。

我确实看到帖子表明 ServiceReferences.ClientConfig与容器 xap 一起打包,这种方法有效。但是,我不相信这是一个巧妙的解决方案。

另一种选择是自动化 ServiceReferences.ClientConfig正如 http://weblogs.asp.net/manishdalal/archive/2009/02/23/silverlight-servicereferences-clientconfig-alternatives.aspx 中所建议的.

这个问题有更好的解决方案吗?

最佳答案

WCF 只会在主应用程序 XAP 的 ClientConfig 文件中查找,而不会在已下载的任何其他 XAP 中查找。因此,您要么需要将配置放在主 XAP 中,要么自己提供配置,您链接的博客文章显示了一种方法。

关于silverlight - 动态加载的 xap 中的 WCF 服务调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6102419/

相关文章:

silverlight - 按需加载 xap 文件

silverlight - 从接口(interface)的 2 个值中按 1 个 bool 值过滤

silverlight - 哪个 Silverlight 控件集更好? Telerik 还是 ComponentArt?

c# - 与 UserControl 的双向绑定(bind)

silverlight - 带有 WCF 的 Silverlight 中的跨域策略错误

c# - 如何使用 MEF 防止模块重复?

c# - 如何根据 app.config 多次导出一个 MEF 插件?

c# - 是否可以使用 MEF RegistrationBuilder 创建 PRISM ModuleExport?