2010-01-06 107 views
0

我有WCF服務庫的功能NHibernate實施,並且在Windows服務主辦。
此外,我有一個Web站點添加了服務引用。調用從測試網站WCF服務方法拋出錯誤

現在,當我打電話從網頁WCF服務方法,我得到以下錯誤:

[FaultException`1: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. 

* Database was not configured through Database method. 
] 
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +7596735 
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +275 
    TeamworksReportService.ITemplateService.ListTemplatesByTemplateType(Int32 userId, TemplateType templateType) +0 
    TeamworksReportService.TemplateServiceClient.ListTemplatesByTemplateType(Int32 userId, TemplateType templateType) 

任何想法?

App.Config中的WCF服務:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Warning, ActivityTracing" 
     propagateActivity="true"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelTraceListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="C:\WCF Service Logs\app_tracelog.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 
    </system.diagnostics> 

    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="netTcp" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000"> 
      <readerQuotas maxDepth="500" maxStringContentLength="50000000" maxArrayLength="50000000" 
         maxBytesPerRead="50000000" maxNameTableCharCount="50000000" /> 
      <security mode="None"></security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 

    <services> 
     <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior" 
     name="ReportingComponentLibrary.TemplateReportService"> 
     <endpoint address="TemplateService" binding="netTcpBinding" bindingConfiguration="netTcp" 
      contract="ReportingComponentLibrary.ITemplateService"></endpoint> 
     <endpoint address="ReportService" binding="netTcpBinding" bindingConfiguration="netTcp" 
      contract="ReportingComponentLibrary.IReportService"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint> 

     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8001/TemplateReportService" /> 
      <add baseAddress="http://localhost:8181/TemplateReportService" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ReportingComponentLibrary.TemplateServiceBehavior"> 
      <serviceMetadata httpGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

服務配置文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <connectionStrings> 
    <add name="connection.connection_string" connectionString="Server=dev01\sql2005;Initial Catalog=TeamWorksReports;User Id=twr;Password=manager2;" /> 
    </connectionStrings> 

    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Warning, ActivityTracing" 
     propagateActivity="true"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelTraceListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="C:\WCF Service Logs\app_tracelog.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 
    </system.diagnostics> 

    <system.serviceModel> 

    <bindings> 
     <netTcpBinding> 
     <binding name="netTcp" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000"> 
      <readerQuotas maxDepth="500" maxStringContentLength="50000000" maxArrayLength="50000000" 
         maxBytesPerRead="50000000" maxNameTableCharCount="50000000" /> 
      <security mode="None"></security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ReportingComponentLibrary.TemplateServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <services> 
     <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior" 
     name="ReportingComponentLibrary.TemplateReportService"> 

     <endpoint address="TemplateService" binding="netTcpBinding" bindingConfiguration="netTcp" 
      contract="ReportingComponentLibrary.ITemplateService"></endpoint> 

     <endpoint address="ReportService" binding="netTcpBinding" bindingConfiguration="netTcp" 
      contract="ReportingComponentLibrary.IReportService"/> 

     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint> 

     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8001/TemplateReportService" /> 
      <add baseAddress ="http://localhost:8181/TemplateReportService" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 

    </system.serviceModel> 
</configuration> 

會話工廠:

private static ISessionFactory SessionFactory 
    { 
     get 
     { 
      if (_sessionFactory == null) 
      { 
       var configuration = new Configuration(); 
       configuration.Configure(@"E:\Source\ResourceTechniques.Applications.TemplateReportingService\ReportingService\bin\Debug\hibernate.cfg.xml"); 

       _sessionFactory = Fluently.Configure(configuration) 
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<TemplateMap>()) 
        .BuildSessionFactory(); 
      } 

      return _sessionFactory; 
     } 
    } 

的hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string">Server=dev01\sql2005;Initial Catalog=TeamWorksReports;User Id=twr;Password=manager2;</property> 
    <property name="show_sql">true</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
    </session-factory> 
</hibernate-configuration> 

回答

2

這與WCF無關 - 這是一個NHibernate問題。看起來您可能試圖在Web.config文件中配置數據庫連接字符串,而不是Windows服務的App.config,這是它需要的位置?

如果您使用的是NHibernate的XML配置文件的配置,是部署了Windows服務,而不是Web應用程序?您嘗試運行的版本是否可以訪問代碼中XML文件的(硬編碼!)路徑?運行服務的帳戶是否具有(硬編碼!)路徑的權限?

最好的辦法是確保hibernate.cfg.xml始終位於同一文件夾中的二進制文件旁邊,並從調用Configure的調用中刪除路徑參數。

+0

感謝您的回覆,我只是缺少添加數據庫連接字符串。但現在當我加入的Windows服務配置文件中的DB連接字符串,我仍然得到同樣的錯誤:-( 我已經編輯我的職務,並加入我的WCF庫和Windows服務的配置文件上面。任何意見? – iniki 2010-01-06 12:01:38

+0

我們「會需要看到其中配置NHibernate的會話工廠代碼。 – 2010-01-06 12:03:05

+0

編輯我的帖子,包括會話出廠配置和hibernate.cfg.xml – iniki 2010-01-06 12:13:24