conflict beteween ValidationBehavior and ExceptionShielding in wcf

Jul 27, 2011 at 1:21 PM

Hi ,

    I am using both validation behavior and Exception shielding in my wcf service . The validation is not working but the exception is working. If i remove the exception shielding from the service contract , validation fault is working fine. Can you tell me why is it not working and solution to solve this issue?

 

 

Thanks,

Buglover

Jul 28, 2011 at 7:09 AM

Hi,

Can you tell us your exact scenario? Are you making validation first then you are throwing an error if the validation fails? It would be better if you can share us your code here :)

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Jul 29, 2011 at 1:41 PM

Hi,

Here is my code of service contract,

[ServiceContract]

[ValidationBehavior]

[ExceptionShielding("ServicePolicy")]

public interface IService1

{

[OperationContract]

[FaultContract(typeof(ValidationFault))]

[FaultContract(typeof(FaultContractValidation))]

string GetData([StringLengthValidator(6, RangeBoundaryType.Inclusive,

8, RangeBoundaryType.Inclusive, MessageTemplate = "Entered string should be of minimum 6 character")] string value);

}

I configured the Service Policy as below,

<add name=" ServicePolicy ">

<exceptionTypes>

<add name="Exception" type="Exception, Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

postHandlingAction="ThrowNewException">

<exceptionHandlers>

<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

logCategory="LogCategory" eventId="1" severity="Warning"

title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"

priority="0" />

<add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

faultContractType="Fault, Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

name="Fault Contract Exception Handler">

<mappings>

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

</mappings>

</add>

</exceptionHandlers>

</add>

</exceptionTypes>

</add>

Thanks,

Vijayasarathi.I

From: AvanadeSupport [email removed]
Sent: 28 July 2011 11:40
To: Vijayasarathi
Subject: Re: conflict beteween ValidationBehavior and ExceptionShielding in wcf [entlib:266707]

From: AvanadeSupport

Hi,

Can you tell us your exact scenario? Are you making validation first then you are throwing an error if the validation fails? It would be better if you can share us your code here :)

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Jul 29, 2011 at 6:33 PM
Hi,
Here is my code of service contract,

[ServiceContract]
[ValidationBehavior]
[ExceptionShielding("ServicePolicy")]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[FaultContract(typeof(FaultContractValidation))]
string GetData([StringLengthValidator(6, RangeBoundaryType.Inclusive,
8, RangeBoundaryType.Inclusive, MessageTemplate = "Entered string should be of minimum 6 character")] string value);
}


I configured the Service Policy as below,

<add name=" ServicePolicy ">
<exceptionTypes>
<add name="Exception" type="Exception, Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="LogCategory" eventId="1" severity="Warning"
title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
<add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
faultContractType="Fault, Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Fault Contract Exception Handler">
<mappings>
<add source="Message" name="{Message}" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>



Thanks,
Vijayasarathi.I



From: AvanadeSupport [mailto:[email removed]
Sent: 28 July 2011 11:40
To: Vijayasarathi
Subject: Re: conflict beteween ValidationBehavior and ExceptionShielding in wcf [entlib:266707]


From: AvanadeSupport

Hi,

Can you tell us your exact scenario? Are you making validation first then you are throwing an error if the validation fails? It would be better if you can share us your code here :)



Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us<https://www.codeplex.com/site/users/contact/AvanadeSupport?OriginalUrl=http://www.codeplex.com/site/users/view/AvanadeSupport>

Read the full discussion online<http://entlib.codeplex.com/discussions/266707#post648748>.

To add a post to this discussion, reply to this email ([email removed]<mailto:[email removed]?subject=[entlib:266707]>)

To start a new discussion for this project, email [email removed]<mailto:[email removed]>

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe<https://entlib.codeplex.com/discussions/266707/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
Aug 1, 2011 at 12:31 PM

Hi,

I was able to reproduce your scenario. Though I can't find a documentation on this, I believe that the method only considers a single fault contract (the one closest to the method name. Try to switch their position and you will notice it). The behavior seems reasonable, since you can't throw multiple exceptions at once. Also, I'm not sure of your exact requirements, but I don't see the need for Exception Fault here since all of your parameter has been already prevalidated.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 2, 2011 at 12:47 PM

Hi,

I am using Validation fault to validate the input parameter and exception shielding to handle the exception thrown from the BAL,DAL.

[ServiceContract]

[ValidationBehavior]

[ExceptionShielding("DefaultServicePolicy")]

public interface IService

{

[OperationContract]

[FaultContract(typeof(Timeout))]

[FaultContract(typeof(InvalidParameter))]

[FaultContract(typeof(UnexpectedServerError))]

[FaultContract(typeof(ValidationFault))]

IList<AddressItem> DoSomething([NotNullValidator] [StringLengthValidator(6, RangeBoundaryType.Inclusive,

8, RangeBoundaryType.Inclusive, MessageTemplate = "Name should be minimum 6 character")] string name);

}

I tried to switch their place and still I am not getting the validation error message in the client side.

Thanks,

Vijayasarathi.I

From: AvanadeSupport [email removed]
Sent: 01 August 2011 17:02
To: Vijayasarathi
Subject: Re: conflict beteween ValidationBehavior and ExceptionShielding in wcf [entlib:266707]

From: AvanadeSupport

Hi,

I was able to reproduce your scenario. Though I can't find a documentation on this, I believe that the method only considers a single fault contract (the one closest to the method name. Try to switch their position and you will notice it). The behavior seems reasonable, since you can't throw multiple exceptions at once. Also, I'm not sure of your exact requirements, but I don't see the need for Exception Fault here since all of your parameter has been already prevalidated.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 4, 2011 at 10:20 AM

I got some strange behavior which I was able to fix. Exception Shielding and Validation works both fine now at my side. I can't seem to find a clue why it won't work. Can you send us a simple repro project for us to investigate?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

 

Aug 9, 2011 at 7:49 AM

Hi ,

I have attached the demo project of my requirement with this mail. kindly check it.

Thanks,

Vijayasarathi.I

From: AvanadeSupport [email removed]
Sent: 04 August 2011 14:50
To: Vijayasarathi
Subject: Re: conflict beteween ValidationBehavior and ExceptionShielding in wcf [entlib:266707]

From: AvanadeSupport

I got some strange behavior which I was able to fix. Exception Shielding and Validation works both fine now at my side. I can't seem to find a clue why it won't work. Can you send us a simple repro project for us to investigate?

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 9, 2011 at 8:43 AM

Hi Vijayasarathi,

We haven't received it yet. Can you create a new email message and attach your demo project there then send it to entlib.support@avanade.com?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 15, 2011 at 5:15 AM

Hi Vijayasarathi,

Sorry for the late response. We already got your solution and we identified that you need to name your Exception Shielding Policy to "WCF Exception Shielding". This is a known bug with Enterprise Library and is already reported to our Issue Tracker (http://entlib.codeplex.com/workitem/28518). I noticed that you already up-voted it. Hope this helps.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us