Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi

I am getting an unexpected error from Enterprise Library Exception Handling Block v5 in WCF.

All I want to do is NotifyRethrow for FaultExeption and FaultException<tdetail>, so client sees the FaultContract on their side

Please read further. Thanks in advance for any help.

I am working on a project where I had to use ExceptionShielding in WCF and not try-catch as we are logging all possible exceptions.

But there are cases where I just have to send information to the client in a Custom Data Fault Contract.

The following is a reproduction project of my actual solution:

Service Interface:


C#
[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [FaultContract(typeof(ServiceFaulty))]
        string GetData(int value);
    }

    [DataContract]
    public class ServiceFaulty
    {
        public Guid ErrorID { get; set; }
        public String Message { get; set; }
    }


Service Implementation:

C#
[ExceptionShielding("Policy")]
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            //Comment first line to trigger second behavior for testing 
            throw new Exception("Service Level Exception Ocured");
            throw new FaultException("Fault Exception Detected");
            return string.Format("You entered: {0}", value);
        }

    }


Following is my configuration:

XML
<exceptionHandling>
    <exceptionPolicies>
      <add name="Policy">
        <exceptionTypes>
          <add name="FaultException" type="System.ServiceModel.FaultException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" />
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                exceptionMessage="Oops we goofed!" faultContractType="WcfService.ServiceFaulty, WcfService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Fault Contract Exception Handler">
                <mappings>
                  <add source="{Guid}" name="ErrorID" />
                </mappings>
              </add>
              <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>



If you see I am trying to test two different behavior.
One for AllException where I want to Log all exceptions and throw a Custom Fault Contract.
The other I want to Bubble Up all the FaultException(s) to the Client Side raised by my code, so I am doing NotifyReThrow.

The first scenario is working fine but in the case I want to bubble up FaultContracts, I am getting the following error:

System.ServiceModel.FaultException: An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: 7e1271c6-c198-428e-aa4f-89c00a194a36

Server stack trace:
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.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)


Also, I am getting the same error If Itry to throw any FaultException<tdetail> object from my service.

The Exception shielding deletes the FaultContract, throws a FaultException object for client and gives me the same Contact your administrator with a Random Guid error as showed above. Again, All I want to do is NotifyRethrow for FaultExeption and FaultException<tdetail>, so client sees the FaultContract on their side
Posted
Comments
Sergey Alexandrovich Kryukov 12-Aug-13 12:17pm    
What is FaultExeption? :-)
—SA
Member 9549287 13-Aug-13 14:56pm    
The second part where you try throwing your object from the service, you have to specify the data members for the service to identify. they'd work fine if you were using it locally within the service, to send them asynchronously, the service has to know the service contract, datacontract and datamembers.as for the first scenario, the error occurs mostly if there is something wrong in the web.config.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900