Why Enterprise Library does not throw FaultException in WCF - wcf

I use WCF service hosted on IIS.
Also, I use fault contracts to send errors to the client (FaultException<'T>)
On the client side I catch FaultException<'T> to show some error to user.
If some unhandled exception being thrown on a server, WCF generates plain FaultException,
so client catches it and shows user "Internal Server Error" message.
Then I began to use Enterprise Library 5.0 for WCF Exception Shielding, and met following issue. Using FaultContractExceptionHandler it is possible to carry all errors to the client, but in case of unhandled exception client receives CommunicationException instead of FaultException. Everything other works ok.
If I turned off exception handling policy (remove ExceptionShielding attibute), client catches FaultExceptions as expected.
Do you know what may be the reason?
Thanks.
PS: Here is a chain of inner exceptions:
CommunicationException -> WebException -> IOException -> SocketException
Message is "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
Web.config
<add name="ServiceException Policy">
<exceptionTypes>
<add name="ServiceLogicException" type="LopService.Contracts.ServiceLogicException, LopService.Contracts, Version=1.0.0.1725, Culture=neutral, PublicKeyToken=null"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
faultContractType="LopService.Contracts.ServiceLogicFaultContract, LopService.Contracts, Version=1.0.0.1725, Culture=neutral, PublicKeyToken=null"
name="Fault Contract Exception Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
Service Class
[ExceptionShielding("ServiceException Policy")]
public partial class LopSoapService
{...
Operation Contract
[OperationContract]
[FaultContract(typeof(DataValidationFaultContract))]
[FaultContract(typeof(ServiceLogicFaultContract))]
int CreateUser(UserDto userDto, IEnumerable<ClaimRecordDto> claimRecords);

This appears to be an issue with Enterprise Library. See this workitem.

Related

WCF There was an error reading from the pipe: The pipe has been ended. (109, 0x6d)

I'm having continuous exception on live server and performance issues.
After enabling trace service log in wcf config file I found 100 of same exceptions.
Basic Information
Activity ID {00000000-0000-0000-0000-000000000000}
Time 2019-08-26 19:59:44.7454
Level Error
Source System.ServiceModel
Process w3wp
Thread 55
Computer PC3
Trace Identifier/Code https://learn.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Diagnostics-ThrowingException
Exception
System.IO.PipeException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Exception Type
System.IO.PipeException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message
There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).
Here is the code I'm using common code
public static WMC.Proxy.BLLService.BLLServiceClient GetBLLServiceClient()
{
var client = new WMC.Proxy.BLLService.BLLServiceClient(settings.GetBinding(settings.BLLServiceBinding), new EndpointAddress(settings.BLLServiceAddress));
SetMaxGraphInItems(client);
return client;
}
How can I fix this?
After a long search on the internet, I found the issue might be relates to the Enum type, which caused serialization failure.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/ee75d768-fd80-4c2b-831e-1d6dd6d4dd17/there-was-an-error-reading-from-the-pipe-the-pipe-has-been-ended-109-0x6d?forum=wcf
WCF NamedPipe CommunicationException - "The pipe has been ended. (109, 0x6d)."
There are many factors contributing to this problem, including data contract, service contract irregularities. It boils down to the fact the there is something wrong with the serialization. Please refer to the below discussion, wish it is useful to you.
http://gonetdotnet.blogspot.com/2014/07/solved-there-was-error-reading-from.html
https://blogs.infosupport.com/there-was-an-error-reading-from-the-pipe-unrecognized-error/
Feel free to let me know if the problem still exists.
Just to be sure, here's web.config section for the trace listener:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"><listeners><add name="xml" /></listeners></source>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"><listeners><add name="xml" /></listeners></source>
<source name="CardSpace"><listeners><add name="xml" /></listeners></source>
<source name="System.IO.Log"><listeners><add name="xml" /></listeners></source>
<source name="System.Runtime.Serialization"><listeners><add name="xml" /></listeners></source>
<source name="System.IdentityModel"><listeners><add name="xml" /></listeners></source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="D:\PutYourPathHere.svclog" />
</sharedListeners>
</system.diagnostics>
Produced file can be inspected using Microsoft Service Trace Viewer.
Try to inspect other events as well. There may be some Contract related issues causing serialization to fail.
If you are absolutely sure that your contract and serialization are fine, then try to reboot "Net.Pipe Listener Adapter" service.
If that does not help, try recycling app pool.
We can see theese issues time to time after new releases or config updates. They are related to wrong communication termination of previous instances.

Is there a way to add WCF svc-less activation with multiple service Activations?

Given the following configuration:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" >
<serviceActivations>
<add relativeAddress="./UserService.svc" service="Mercato.KnowledgeKube.WebSvc.Service.KnowledgeuserManagerService" factory="Mercato.KnowledgeKube.WebSvc.WCF.KnowledgeServiceHostFactory" />
<add relativeAddress="./ProductService.svc" service="Mercato.KnowledgeKube.WebSvc.Service.ProductManagerWebServices" factory="Mercato.KnowledgeKube.WebSvc.WCF.KnowledgeServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
The first of the two ./UserService is reachable and I can create a Service Reference to it, but the ProductServce is not reconcilable. What am I doing wrong here?
EDIT
here is the Exception:
There was no endpoint listening at http://localhost/KnowledgeWebService/ProductService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution
and adding the service reference again.
There wasn't an endpoint listening because......I hadn't decorared the product service with the relevant attributes. I was looking for more complex problems first.

VS2010 "Update Service Reference" to WCF where behavior extensions inspect and change messages

I'm using an encrypted timestamp to secure communications between a WCF service in my web server and another in the 'mid-tier'. In the calling service (the client in this exchange) I'm using a DLL whose class inherits System.ServiceModel.Configuration.BehaviorExtensionElement to provide functionality implementing System.ServiceModel.Description.IEndpointBehavior and System.ServiceModel.Dispatcher.IClientMessageInspector. This is glued in via the web.config file with the sections
<extensions>
<behaviorExtensions>
<add name="MessageInspectorBehavior" type="MessageInspectorDLL.MessageInspectorBehaviorExtensionElement, MessageInspectorDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<endpointBehaviors>
<behavior name="MessageInspectorEndpointBehavior">
<MessageInspectorBehavior />
</behavior>
</endpointBehaviors>
and then these are hooked up to the mid-tier WCF with entries like this one
<client>
<endpoint address="http://blah.cloudapp.net:8080/BlahService.svc"
behaviorConfiguration="MessageInspectorEndpointBehavior" binding="customBinding"
bindingConfiguration="CustomBinding_BlahService"
contract="BlahServiceReference.BlahService"
name="CustomBinding_BlahService" />
In the mid-tier there's a similar story with a System.ServiceModel.Dispatcher.IClientMessageInspector decrypting the time stamp and either processing the request or throwing a System.ServiceModel.FaultException with the error message "Invalid stamp".
This follows code examples at http://msdn.microsoft.com/en-us/library/ms733747.aspx and http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx
Now I have changed the mid-tier WCF. Some changes are simple (e.g. correcting a spelling mistake in a method name "retrive" -> "retrieve") while some adds more substantial functionality and I want to update the service recerences in the client. In VS2010 I right-click on the service references that will need updating and select "Update Service Reference". VS2010 connects to the mid-tier WCF ("downloading service information") and then throws the error
The configuration for the service reference could not be updated due to the following issue: The type 'MessageInspectorDLL.MessageInspectorExtensionElement, MessageInspectorDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'MessageInspectorBehavior' could not be loaded. (C:\TFS\Blah\Blah\web.config line 80)
What's wrong? Is there something I need to set up for the update service reference to correctly use the message inspector DLL?
Though it is possible that the DLL or the web.config have errors that seems unlikely since the client will connect to the previous mid-tier which is up on Azure, and that has the same encrypted timestamp inspection.
I've found an answer. Adding the MessageInspectorDLL as a reference to the ASP application fixed it for me.

WCF Service is showing error after implemented in IIS

In my project I am using Enterprise Library to connect to database. It is working fine when I run the application from Visual Studio directly.
But this is showing error connecting to database when hosted in IIS on same machine. I have added log trace and got the following error
Resolution of the dependency failed, type =
"Microsoft.Practices.EnterpriseLibrary.Data.Database", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The type Database cannot be constructed.
You must configure the container to supply this value.
----------------------------------------------- At the time of the
exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)
| Exception:Microsoft.Practices.ServiceLocation.ActivationException:
Activation error occured while trying to get instance of type
Database, key "" --->
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the
dependency failed, type =
"Microsoft.Practices.EnterpriseLibrary.Data.Database", name =
"(none)". Exception occurred while: while resolving. Exception is:
InvalidOperationException - The type Database cannot be constructed.
You must configure the container to supply this value.
----------------------------------------------- At the time of the
exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)
---> System.InvalidOperationException: The type Database cannot be
constructed. You must configure the container to supply this value.
at
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext
context, SelectedConstructor selectedConstructor) at
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext
context, NamedTypeBuildKey buildKey) at
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type
t, Object existing, String name, IEnumerable1 resolverOverrides)
--- End of inner exception stack trace --- at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name, IEnumerable1 resolverOverrides) at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String
name, IEnumerable`1 resolverOverrides) at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type
serviceType, String key) --- End of inner exception stack trace ---
at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type
serviceType, String key) at
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String
key) at
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String
name)
My web.config of service is contains as below
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
<dataConfiguration defaultDatabase="OracleConnection">
<providerMappings>
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>
</providerMappings>
</dataConfiguration>
<connectionStrings>
<add name="OracleConnection" providerName="Oracle.DataAccess.Client" connectionString="User Id=***;Password=****;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*****)(PORT=1500)) (CONNECT_DATA=(SERVER = DEDICATED) (SERVICE_NAME =*****)));"/>
<add name="SybaseConnection" connectionString="providerName=Sybase.ASEOLEDBProvider;Server=****;Port=5050;Catalog=**;User Id=***;Password=****"/>
</connectionStrings>
I tried a lot but unable to find the cause of issue. :(
I checked the permission on the folder and Everyone has full control. WCF Service in IIS Anonymous access is enabled.
Could anyone please help?
The assembly you are using cannot find one of the assemblies it depends on, make sure all dependencies are either in the GAC or in the bin folder of your web app.
When i enabled 32 bit applications in IIS the error has been changed to
ORA-12638: Credential retrieval failed
The connection string is correct which is working with visual studio.
Is there any setting we need to do in Oralce part to acces connection from IIS?
This worked fine when updated sqlnet.ora file of oracle.

Getting debug output from WCF 4 REST Template

I'm trying to see the exception that's being thrown in my WCF service but all I get from the response is:
"The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs."
Since I'm doing it the "REST" way, I don't have these options in my web.config. So, how can I enable "IncludeExceptionDetailInFaults" when using the WCF 4 REST Template?
Here's what I came up with:
Under the standardEndpoint in your web.config, turn on faultExceptionEnabled
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true">
Then, for custom messages to show, the thrown exceptions must be a FaultException. Here's an example of one that I use:
if (!Enum.GetNames(typeof(Models.Games.GsfCurrencyPrice.Sections)).Contains(section)) throw new FaultException<ArgumentException>(new ArgumentException("Value must be one of the following: " + string.Join(", ", Enum.GetNames(typeof(Models.Games.GsfCurrencyPrice.Sections))), "section"));
which produces the following response when thrown:
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Sender</Value></Code><Reason><Text xml:lang="en-US">The creator of this fault did not specify a Reason.</Text></Reason><Detail><ArgumentException xmlns="http://schemas.datacontract.org/2004/07/System" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><ClassName i:type="x:string" xmlns="">System.ArgumentException</ClassName><Message i:type="x:string" xmlns="">Value must be one of the following: Buy, Sell</Message><Data i:nil="true" xmlns=""/><InnerException i:nil="true" xmlns=""/><HelpURL i:nil="true" xmlns=""/><StackTraceString i:nil="true" xmlns=""/><RemoteStackTraceString i:nil="true" xmlns=""/><RemoteStackIndex i:type="x:int" xmlns="">0</RemoteStackIndex><ExceptionMethod i:nil="true" xmlns=""/><HResult i:type="x:int" xmlns="">-2147024809</HResult><Source i:nil="true" xmlns=""/><WatsonBuckets i:nil="true" xmlns=""/><ParamName i:type="x:string" xmlns="">section</ParamName></ArgumentException></Detail></Fault>
Hope this helps.