2017-03-22 2 views
0

Ich habe einen WCF-Dienst in einer Bibliothek und einem Windows-Dienst definiert, die diesen WCF-Dienst selbst hosten. Ich benutze Entity Framework 6 für Data Layer innerhalb derselben Bibliothek.WCF und Entity Framework 6 Konfigurationsdatei

Wer konnte bestätigen, wo ich die Verbindungszeichenfolge für EF benötigt definiert? Inside App.config meines Self-Hosting-Windows-Dienstes? dh WindowsService.exe.config ...

Ich möchte, dass diese Verbindungszeichenfolge würde für alle meine WCF-Clients ...

Vielen Dank für Ihre Kommentare vorhanden sein!

Antwort

0

Ok, mein Problem wurde schließlich überhaupt nicht auf app.config (s) bezogen.

Ich habe meinen WCF-Dienst nicht korrekt aufgerufen.

Um die Generierung/Verwendung von Proxies zu vermeiden, verwende ich ChannelFactory() in meinem WCF-Dienst, da ich sowohl Server als auch Clients verwalte. Dieser WCF-Dienst ist throw MVVM Licht mit folgendem Code implementiert:

ViewModelLocator.cs:

public class ViewModelLocator 
    { 
     static ViewModelLocator() 
     { 
      ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); 

      //Define data access (wcf service) for design mode 
      if (ViewModelBase.IsInDesignModeStatic) 
      { 
       SimpleIoc.Default.Register<IService, Design.DesignDataService>(); 
      } 
      ... 
    } 

WcfServer Klasse:

public class WcfServer : IDisposable 
    { 
     //Wcf connection 
     private ChannelFactory<IService> _wcfFactory = null; 

     /// <summary> 
     /// Gets the DataService proxy from MVVMLight SimpleIOC instance. 
     /// </summary> 
     public IService DataService 
     { 
      get 
      { 
       return SimpleIoc.Default.GetInstance<IService>()??null; 
      } 
     } 

     /// <summary> 
     /// Add a Wcf server for a customer, a url and a server name 
     /// </summary> 
     /// <param name="customerName"></param> 
     /// <param name="serverName"></param> 
     /// <param name="urlServer"></param> 
     /// <param name=""></param> 
     public WcfServer(string customerName, string serverName, string urlServer) 
     { 
      _customerName = customerName; 
      ServerName = serverName; 
      UrlServer = urlServer; 
     } 

     /// <summary> 
     /// Connect to wcf service 
     /// </summary> 
     /// <exception cref="ArgumentNullException">Thrown if a null exception is thrown all over Connect method</exception> 
     /// <exception cref="ObjectDisposedException">Thrown if an object is disposed all over Connect method</exception> 
     /// <exception cref="System.ServiceModel.Security.MessageSecurityException">Thrown if authentication failes with username/password over ssl</exception> 
     /// <exception cref="CommunicationObjectFaultedException">Faulted Exception on exception from ChannelFactory==>CreateChannel</exception> 
     /// <exception cref="System.InvalidOperationException">Invalid Operation Exception</exception> 
     /// <exception cref="Exception">Other exception</exception> 
     /// <returns>Returns true if connected</returns> 
     public bool Connect() 
     { 
      try 
      { 
       ... 

       EndpointAddress endpointAddress = new EndpointAddress(new Uri(UrlServer)); 
       if (_wcfFactory == null) 
       { 
        _wcfFactory = new ChannelFactory<IService>(WCFSharedConfiguration.ConfigureBindingWithSimplehttps(), endpointAddress); 

        //Open ChannelFactory 
        _wcfFactory.Open(); 

        //Define Faulted handler 
        _wcfFactory.Faulted += FactoryFaulted; 
       } 
       else 
        //Log + return 
       if (!ViewModelBase.IsInDesignModeStatic) 
       { 
        //If we are not in Design (means blend or VS IDE) 
        SimpleIoc.Default.Register<IService>(() => _wcfFactory.CreateChannel(), true); 
       } 
      } 
      catch (Exception ex) 
      { 
       //Log 
       throw; 
      } 
      return true; 
     } 

     /// <summary> 
     /// Disconnect current channel 
     /// </summary> 
     /// <exception cref="TimeoutException">Timeout</exception> 
     /// <exception cref="CommunicationObjectFaultedException">Faulted Exception on exception from ChannelFactory==>CreateChannel</exception> 
     /// <exception cref="Exception">Other exception</exception> 
     /// <returns>True if successfull</returns> 
     public bool Disconnect() 
     { 
       ... 
     } 

Mai, es hilft!