Сбой вызова службы WCF в динамически загружаемом xap

#silverlight #mef #dynamically-loaded-xap

#silverlight #mef #динамически загружаемый xap

Вопрос:

У меня есть контейнер / главное приложение Silverlight. Этот контейнер динамически загружает xaps и вызывает определенные пользовательские элементы управления в загруженных xaps. Некоторые из этих пользовательских элементов управления вызывают службу 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 .

Есть ли лучшее решение этой проблемы?

Ответ №1:

WCF будет искать XAP основного приложения только в файле ClientConfig, а не в каких-либо дополнительных XAP, которые были загружены. Таким образом, вам нужно либо поместить конфигурацию в основной XAP, либо предоставить конфигурацию самостоятельно, что в сообщении в блоге, на которое вы ссылаетесь, показан один из способов сделать.

Комментарии:

1. Прежде всего, спасибо.. Какие другие способы вы предлагаете, есть ли способ использовать MEF