Enterprise Library and WCF

Topics: Data Access Application Block, Exception Handling Application Block, Logging Application Block
Jul 16, 2008 at 6:10 PM
I have two projects using EL 4, one do log routines the other use exception policy and data access, both are configured under a third project, my WCF project, the web.config its configured to service and use EL 4.
Web.config at WCF Project:

<configuration

 

>

 

<

 

 

configSections>

 

<

 

 

section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />

 

<

 

 

section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" />

 

<

 

 

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />

 

<

 

 

sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

<

 

 

sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

<

 

 

section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

 

<

 

 

sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

<

 

 

section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />

 

<

 

 

section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

 

<

 

 

section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

 

<

 

 

section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

 

</

 

 

sectionGroup>

 

</

 

 

sectionGroup>

 

</

 

 

sectionGroup>

 

</

 

 

configSections>

 

<

 

 

loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

<

 

 

listeners>

 

<

 

 

add fileName="C:\bdslog\componente.log" header="----------------------------------------" footer="----------------------------------------" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" name="FlatFile TraceListener" />

 

<

 

 

add source="BdshDal" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" name="Formatted EventLog TraceListener" />

 

</

 

 

listeners>

 

<

 

 

formatters>

 

<

 

 

add template="Timestamp: {timestamp}&#xD;&#xA;{message}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" name="Text Formatter" />

 

</

 

 

formatters>

 

<

 

 

logFilters>

 

<

 

 

add enabled="false" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging" name="LogEnabled Filter" />

 

</

 

 

logFilters>

 

<

 

 

categorySources>

 

<

 

 

add switchValue="All" name="Data Access">

 

<

 

 

listeners>

 

<

 

 

add name="FlatFile TraceListener" />

 

</

 

 

listeners>

 

</

 

 

add>

 

<

 

 

add switchValue="All" name="General">

 

<

 

 

listeners>

 

<

 

 

add name="Formatted EventLog TraceListener" />

 

</

 

 

listeners>

 

</

 

 

add>

 

</

 

 

categorySources>

 

<

 

 

specialSources>

 

<

 

 

allEvents switchValue="All" name="All Events" />

 

<

 

 

notProcessed switchValue="All" name="Unprocessed Category" />

 

<

 

 

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

 

 

listeners>

 

<

 

 

add name="Formatted EventLog TraceListener" />

 

</

 

 

listeners>

 

</

 

 

errors>

 

</

 

 

specialSources>

 

</

 

 

loggingConfiguration>

 

<

 

 

exceptionHandling>

 

<

 

 

exceptionPolicies>

 

<

 

 

add name="Data Access Policy">

 

<

 

 

exceptionTypes>

 

<

 

 

add type="System.Data.DataException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None" name="DataException">

 

<

 

 

exceptionHandlers>

 

<

 

 

add logCategory="Data Access" eventId="900" severity="Error" title="BdshDal Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging" name="Logging Handler" />

 

</

 

 

exceptionHandlers>

 

</

 

 

add>

 

<

 

 

add type="System.Data.Common.DbException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None" name="DbException">

 

<

 

 

exceptionHandlers>

 

<

 

 

add logCategory="Data Access" eventId="901" severity="Error" title="BdshDal Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging" name="Logging Handler" />

 

</

 

 

exceptionHandlers>

 

</

 

 

add>

 

<

 

 

add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" name="Exception" />

 

</

 

 

exceptionTypes>

 

</

 

 

add>

 

</

 

 

exceptionPolicies>

 

</

 

 

exceptionHandling>

 

<

 

 

connectionStrings>

 

<

 

 

add name="bds" connectionString="Server=DBBDSSVR;Database=BDS;User Id=sa;Password=sadbbdssvr!;Integrated Security=false"

 

 

 

 

providerName="System.Data.SqlClient" />

 

</

 

 

connectionStrings> 

 

 

 

The projects that uses EL 4 already works with a fourth project in my machine, but when I put code to access my WCF service in a client that client give me the following error:

The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Data Access Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)

Help  me plz, I'm getting crazy with this error.
Jul 16, 2008 at 6:30 PM
Hi,

It's really hard to understand your situation from your description. You mention what seem to be two libraries used by a WCF service but you're getting the error on the client; is that right? That would make the web.config irrelevant unless the exception you're getting is a fault when calling the service, in which case the client itself should not matter. Can you explain exactly where you're getting the error?

Also, since the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging assembly is not typically linked to projects using the EHAB, make sure you're deploying it to the app that is getting the failure.

Fernando

Jul 16, 2008 at 6:53 PM
Hi Fernando,

Yes two libraries, one to log and one to do the data access. And yes again the fault is when I'm calling the service, exactly when I call the GetAtributoData mehtod from the WCF service in the client:

ServiceClient

 

client = new ServiceClient("WSHttpBinding_IService");

 

 

DataSet ds = client.GetAtributoData();

This method acess my database retrives data and send a dataset back to the wcf service that returns it to the client. Both libraries have the necessary assemblies to execute and WCF service copy that assemblies when I get the reference to the libraries. That includes EL4 assemblies:
Common
Data
Exception
Logging
ObjectBuilder2
Unity

I can't debug the WCF side because it is in a separate machine.

Any ideas?

Thanks.

Navarro.

 

Jul 16, 2008 at 7:10 PM
I forgot to say that when WCF service is hosted on my machine not in a server, the method works fine, the server doesn't have el4 installed, but I think this isn't a problem is it?

Jul 16, 2008 at 7:13 PM

Hi,

As I mentioned in my previous email, make sure the assembly Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging is deployed with your app. It's not in your list below, but it is required by your configuration.

Fernando


vnavarro87 wrote:
Hi Fernando,

Yes two libraries, one to log and one to do the data access. And yes again the fault is when I'm calling the service, exactly when I call the GetAtributoData mehtod from the WCF service in the client:

ServiceClient

 

client = new ServiceClient("WSHttpBinding_IService");

 

 

 

DataSet ds = client.GetAtributoData();

This method acess my database retrives data and send a dataset back to the wcf service that returns it to the client. Both libraries have the necessary assemblies to execute and WCF service copy that assemblies when I get the reference to the libraries. That includes EL4 assemblies:
Common
Data
Exception
Logging
ObjectBuilder2
Unity

I can't debug the WCF side because it is in a separate machine.

Any ideas?

Thanks.

Navarro.

 

 




Jul 16, 2008 at 7:50 PM

Hi,

I add the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging  to the WCF project I thought it was there because of the logging library, but I add the libraries referencing the data access library .dll that didn't have all the assemblies in the log library (data access uses log), including the guy that you mention, but now I have the following at the same place:

No corresponding start element is open.

Inner Exception

Server stack trace:
   at System.Xml.XmlBaseReader.ReadEndElement()
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IService.GetAtributoData(GetAtributoDataRequest request)
   at ServiceClient.IService.GetAtributoData(GetAtributoDataRequest request) in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\Service.cs:line 305
   at ServiceClient.GetAtributoData() in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\Service.cs:line 311
   at ExcelWCF.ThisAddIn.LoadDataSet() in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\ThisAddIn.cs:line 34

Thanks.

Navarro.

Jul 16, 2008 at 8:01 PM
Edited Jul 16, 2008 at 8:05 PM
It seems to me the original issue with EntLib is solved and this new one is really about the application and the kind of information being transmitted. If you're using DataSets in your message contract, this post may give you some hints http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1503723&SiteID=1.

Fernando


vnavarro87 wrote:

Hi,

I add the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging  to the WCF project I thought it was there because of the logging library, but I add the libraries referencing the data access library .dll that didn't have all the assemblies in the log library (data access uses log), including the guy that you mention, but now I have the following at the same place:

No corresponding start element is open.

Inner Exception

Server stack trace:
   at System.Xml.XmlBaseReader.ReadEndElement()
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IService.GetAtributoData(GetAtributoDataRequest request)
   at ServiceClient.IService.GetAtributoData(GetAtributoDataRequest request) in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\Service.cs:line 305
   at ServiceClient.GetAtributoData() in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\Service.cs:line 311
   at ExcelWCF.ThisAddIn.LoadDataSet() in C:\Users\vnavarro\Documents\Visual Studio 2008\Projects\ExcelWCF\ExcelWCF\ThisAddIn.cs:line 34

Thanks.

Navarro.




Jul 16, 2008 at 8:28 PM
Hi,

I solved the problem, thanks a lot for the help.

Navarro.