tags:

views:

280

answers:

2

Hello there,

I have WCF Service Library implemented in Fluent NHibernate and hosted under Windows Service.
Also, I have a WebSite to which Service reference is being added.

Now, when I am calling WCF Service methods from WebSite, I get the following error:

[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)

Any ideas?

App.Config in WCF Service:

    <?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>

Service Configuration file:

    <?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>

Session Factory:

    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> 
+1  A: 

It's nothing to do with WCF - it's an NHibernate problem. Looks like you may have attempted to configure the DB connection string in the Web.config file, rather than the App.config for the Windows service, which is where it needs to be?

If you're configuring using an NHibernate XML configuration file, is that deployed with the Windows service rather than the web application? Does the version you are trying to get running have access to the (hard-coded!) path to the XML file in your code? Does the account under which the service runs have permissions on the (hard-coded!) path?

Your best bet is to make sure that hibernate.cfg.xml is always alongside your binaries in the same folder, and remove the path parameter from the call to Configure.

David M
Thank for your reply, I was just missing to add DB connection string. But now when I have added the DB Connection String in Windows Service config file, I am still getting same error :-(I have edited my post and added config file of my WCF Library and Windows Service above. Any comments?
inutan
We'll need to see the code where you configure NHibernate's session factory.
David M
Edited my post to include Session factory configuration and hibernate.cfg.xml
inutan
Check my edit...
David M
Yes, I had manually copied hibernate.cfg.xml in Windows Service Installation Folder. Also, because I have all these apps locally on my machine, it should have access to xml file at run-time.
inutan
One more edit - I think we're getting there...
David M
not sure, but I checked the Windows Service logon Property and it was set to : Local System Account. I tried changing that to ASPNET user. but when I try to start the service for ASPNET user, it says.. Service cann't be started due to logon failure... Not sure what I am missing :(
inutan
One more edit... ;)
David M
:-) that error is gone now, when I changed the config file path. but now another error: An exception occurred during configuration of persistence layer.
inutan
Need more details than that...
David M
inutan
If you just write a unit test or other test harness to call the ListTemplatesByTemplateType method directly, does that still error? I don't think this has anything to do with either WCF or websites...
David M
Yes, works fine if I call this method directly using unit test. Me not having a single clue why this error is coming up :-( It may be some NHibernate issue.
inutan
What version of NHibernate? 2.1.x?
David M
Yes, and FluentNH version 1.0
inutan
And have you made sure to copy the proxy factory DLLs to the output folder of the Windows service? If you haven't changed from the default, this would involve NHibernate.ByteCode.Castle.dll and some Castle.*.dll files (off the top of my head).
David M
Thanks a lot David for your help. Two changes finally resolved the issue: 1. Yes, it was some missing NH dll in Reporting Service Output folder. 2. It was looking for hibernate.cfg.xml in System32, to change that I added Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory; in Service OnStart(). Thank you!
inutan
Pleasure - really glad we got you there in the end.
David M
A: 

Seems like ur using SQL Server to host ur session, and you have not configured sql server for session state in ur wcf service.

Following links may help:

Session-State Modes

http://msdn.microsoft.com/en-us/library/ms178586.aspx

HOW TO: Configure SQL Server to Store ASP.NET Session State http://support.microsoft.com/kb/317604

Nitin Midha