2010-01-06 106 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