Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF service call within a dynamically-loaded-xap fails

I have a container/master Silverlight application. This container dynamically downloads xaps and calls out to specific user-controls within the downloaded xaps. Some of these user-controls call out to a WCF service hosted at server.

The following error arises when the user controls within the downloaded xap call out to the WCF service:

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:
          ...

The exception tells me that the ServiceReferences.ClientConfig is not visible somehow... even though it is packaged within the downloaded xap.

I did see posts that suggest that the ServiceReferences.ClientConfig be packaged with the container xap and this approach works. However I am not convinced that this is a neat solution.

The other alternative is to automate the ServiceReferences.ClientConfig as suggested in http://weblogs.asp.net/manishdalal/archive/2009/02/23/silverlight-servicereferences-clientconfig-alternatives.aspx.

Is there a better solution to this problem?

like image 301
Venkat Srinivasan Avatar asked Nov 14 '22 22:11

Venkat Srinivasan


1 Answers

WCF will only look in the ClientConfig file for the main application XAP, not in any additional XAPs that have been downloaded. So you either need to put the config in the main XAP or supply the configuration yourself, which the blog post you linked shows one way of doing.

like image 170
Daniel Plaisted Avatar answered Dec 30 '22 10:12

Daniel Plaisted