WCF Exception Shielding Issues with Enterprise Library 4.1

Topics: Exception Handling Application Block
Jan 13, 2009 at 6:40 PM
I am trying to use Enterprise Library 4.1 for ExceptionShielding in the following code. This code is only throwing the FaultContract but not the FaultContract<Common.WCF.ServiceContracts.ServiceFault>.

I would really appreciate any help on this.

Thanks in Advance.
Bunty

Service Contract

[

ServiceContract(Name = "IOrdersService")]

 

[

ExceptionShielding("WCF Exception Shielding")]

 

 

public interface IOrdersService

 

{

[

OperationContract(Name = "CreateOrder")]

 

[

FaultContract(typeof(Common.WCF.ServiceContracts.ServiceFault))]

 

 

int CreateOrder(string currency, double amount);

 

}

Fault Contract

[

DataContract(Name = "ServiceFault")]

 

 

public class ServiceFault

 

{

 

public ServiceFault()

 

{

}

 

private string message;

 

 

private IDictionary data;

 

 

private Guid id;

 

[

DataMember]

 

 

public string MessageText

 

{

 

get { return message; }

 

 

set { message = value; }

 

}

[

DataMember]

 

 

public IDictionary Data

 

{

 

get { return data; }

 

 

set { data = value; }

 

}

[

DataMember]

 

 

public Guid Id

 

{

 

get { return id; }

 

 

set { id = value; }

 

}

}


WCF Exception Configuration

<

 

exceptionHandling>

 

<

 

exceptionPolicies>

 

<

 

add name="WCF Exception Shielding">

 

<

 

exceptionTypes>

 

<

 

add type="System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"

 

 

 

postHandlingAction="ThrowNewException" name="InvalidOperationException">

 

<

 

exceptionHandlers>

 

<

 

add exceptionMessage="My Custom Error Message" faultContractType="Common.WCF.ServiceContracts.ServiceFault, Common.WCF.ServiceContracts"

 

 

 

type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"

 

 

 

name="DefaultFaultContract Handler">

 

<

 

mappings>

 

<

 

add source="{Guid}" name="Id" />

 

<

 

add source="{Message}" name="MessageText" />

 

</

 

mappings>

 

</

 

add>

 

</

 

exceptionHandlers>

 

</

 

add>

 

</

 

exceptionTypes>

 

</

 

add>

 

</

 

exceptionPolicies>

 

</

 

exceptionHandling>

 



Jan 14, 2009 at 11:16 AM

Hi,

Let me just clarify, are you saying that your code just only throws a FaultException and not FaultException<ServiceFault>? Can you please post your client code? I tried your code, I modified it a bit, I throw a InvalidOperationException on one OperationContract. I have this code in my client:

 

OrdersServiceClient client = new OrdersServiceClient();
try
{
client.DoSomething();
}
catch (FaultException<ServiceFault> ex)
{
}

 When I view the detail of the catched exception, it say that its a type of FaultException<ServiceFault>.

Here is my reference:
http://dotnetraj.spaces.live.com/Blog/cns!8FAA9A469DC71DC!289.entry


Hope this Helps.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jan 14, 2009 at 4:51 PM
Thanks for your help... but it was a enterprise library DLL version and reference issue which I was able to fix. The code seems to be working now.
Thanks,
Bunty

On Wed, Jan 14, 2009 at 4:16 AM, AvanadeSupport <notifications@codeplex.com> wrote:

From: AvanadeSupport

Hi,

Let me just clarify, are you saying that your code just only throws a FaultException and not FaultException<ServiceFault>? Can you please post your client code? I tried your code, I modified it a bit, I throw a InvalidOperationException on one OperationContract. I have this code in my client:

OrdersServiceClient client = new OrdersServiceClient();
try
{
client.DoSomething();
}
catch (FaultException<ServiceFault> ex)
{
}

When I view the detail of the catched exception, it say that its a type of FaultException<ServiceFault>.

Here is my reference:
http://dotnetraj.spaces.live.com/Blog/cns!8FAA9A469DC71DC!289.entry


Hope this Helps.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Read the full discussion online.

To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)

To start a new discussion for this project, email entlib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jan 15, 2009 at 3:18 AM
Thanks for the Info.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com