Not Throws FaultException<T>, if I host WCF Services in IIS

Topics: Exception Handling Application Block
Jul 7, 2008 at 4:51 PM
I have one Validation Exception and Validation Fault which has same properties (So that EntLib4.0 maps them automatically).
I added a policy to config file to map ValidationException and ValidationFault.

Scenario1:
When I hosted my WCF Services using ServiceHost class in ConsoleAppliction, at client side i will be able to catch FaultException<ValidationFault> and I am able to access the mapped data.
It is Excellent:

Scenario2:

When  I hosted my WCF in Web Application using svc file and added same policy to map ValidationException and ValidationFault in config file.
I am not able to catch FaultException<ValidationFault> at client. It is throwing FaultException which has a generic message to contact system administrator with a error code as GUID.

What I am doing wrong here?
please suggest me.
Thanks
Venki


Jul 7, 2008 at 6:07 PM
Hi,

It's hard to tell what you're doing wrong with the information you've provided.

Here's some extra information that would help:
  • Does it work with the development web server?
  • What do you mean by "added same policy to map ValidationException and ValidationFault in config file"? There is no such validation exception in EntLib, and ValidationFaults are created by the VAB's ValidationParametersInspector.
  • What does your web.config look like? Are you using the same config settings when you use the ServiceHost approach?

Fernando



venki_gun wrote:
I have one Validation Exception and Validation Fault which has same properties (So that EntLib4.0 maps them automatically).
I added a policy to config file to map ValidationException and ValidationFault.

Scenario1:
When I hosted my WCF Services using ServiceHost class in ConsoleAppliction, at client side i will be able to catch FaultException<ValidationFault> and I am able to access the mapped data.
It is Excellent:

Scenario2:

When  I hosted my WCF in Web Application using svc file and added same policy to map ValidationException and ValidationFault in config file.
I am not able to catch FaultException<ValidationFault> at client. It is throwing FaultException which has a generic message to contact system administrator with a error code as GUID.

What I am doing wrong here?
please suggest me.
Thanks
Venki





Jul 7, 2008 at 10:01 PM

Hi Fernando:
Here are answers to your questions:
1. It is not working even in Development web server
2. ValidationExcpetion and ValidationFault are my business exception and associated fault.
3. It was same.

But now, Somehow it is working fine today even I set 

 

<

serviceDebug includeExceptionDetailInFaults="true" />

But, I am not sure what was the reason.

Thanks
Venki

 

Jul 7, 2008 at 10:05 PM

Have you declared the fault in your service interface?

Fernando


venki_gun wrote:

Hi Fernando:
Here are answers to your questions:
1. It is not working even in Development web server
2. ValidationExcpetion and ValidationFault are my business exception and associated fault.
3. It was same.

But now, Somehow it is working fine today even I set 

 

<

 

serviceDebug includeExceptionDetailInFaults="true" />

But, I am not sure what was the reason.

Thanks
Venki

 

 




Jul 8, 2008 at 3:07 AM
Yes, I am.
Jul 8, 2008 at 12:31 PM
Hi,

I'd like to understand this. Is it working only when you enable the debug setting to include the exception detail?

Can you create a stand-alone repro that shows this?

Fernando


But now, Somehow it is working fine today even I set 

 

<

 

serviceDebug includeExceptionDetailInFaults="true" />

But, I am not sure what was the reason.

Thanks
Venki

 

 




Jul 25, 2008 at 4:25 PM

Hi Fernando,
Sorry, i was on vacation, sorry for late reply.

It was not consistent. If my project points to EntLib Source Code then it throws always FaultException<T>. When I point to EntLib 4.0 assemblies (GAC), the following problems i face..
1. When I point my project to use EntLib4.0 source code, it is throwing FaultException<T>. To make this work, I have to create Default Constructors to my Fault Contracts otherwise EnsureDefaultConstructor() is throwing MissingMethod exception.

2. If my Application points to EntLib 4.0 GAC Assemblies, It always throws FaultException not FaultException<T>. The exception says generic message "Contact System Administrator". Do I need to set some configuration?

Thanks in advance.
Venky

Jul 25, 2008 at 4:49 PM
Hi,

Can you post a sample project showing this?

Just to make sure, you are updating the configuration to match EntLib's assemblies when you switch from source to signed binaries, aren't you?

Regards,
Fernando
Jul 25, 2008 at 7:16 PM
Yep, it was issue with config  PublicKeyToken (Now, this is working good).

I have 3 FaultContracts to 3 Exceptions. I am throwing only one exception but EntLib is instantiating 3 times for 3 faultcontracts, irrespective of using them.
Did anybody reported this before? Or I am doing something wrong? B'coz this may be a performance hit for me.
Suggest me.
Thanks
Venky
Aug 1, 2008 at 6:33 PM
Hi Fernando,
I am facing this problem again. I am doing following things:
Step1:

public void ValidateForWorkFlowPreview(Evaluation evaluation) {

PopulateAllValidationMessageStruct(ValidateTeam(evaluation));

PopulateAllValidationMessageStruct(ValidateAnswerSet(evaluation));

 

if (_allValidationMessageStruct.MessageCodes.Count > 0 && _fieldList.Count > 0)

 

{

 

string message = GetLocalizedMessageFromDb(DisplayResourceClass, "2007");

 

 

string operation = "ValidateForWorkFlowPreview";

 

 

string messageDefinitionNumber = "2007";

 

Guid newGuid = Guid.NewGuid();

 

Exception exception = new Exception(message);

 

//throw Business Exception

 

ValidationException validationException = new ValidationException(exception, operation, messageDefinitionNumber, newGuid, null, _fieldList);

 

throw validationException;

 }

}

 

Step2: Signed ExceptionShielding attr in Service Impl:

[

ExceptionShielding("EvaluationPolicy")]

 

 

public partial class EngagementEvaluationService

 

 

{

//Here i am calling my business method which throws ValidationException

 

 

}

Step3: Using EntLib.exe i modified config file like this.

Here is my web.config:

 <?xml version="1.0"?>
<configuration>
 <configSections>
  <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  <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>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="EvaluationPolicy">
    <exceptionTypes>
     <add type="Kpmg.Nggc.Common.ExceptionManagement.ValidationException, Kpmg.Nggc.Common.ExceptionManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cdcbae00f327936c" postHandlingAction="NotifyRethrow" name="ValidationException">
      <exceptionHandlers>
       <add exceptionMessage="" faultContractType="Kpmg.Nggc.Common.FaultContracts.ValidationFault, Kpmg.Nggc.Common.FaultContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cdcbae00f327936c" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Fault Contract Exception Handler"/>
      </exceptionHandlers>
     </add>
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>
 <system.web>
  <compilation debug="true">
   <assemblies>
    <!--<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.ObjectBuilder2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.Unity, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   </assemblies>
  </compilation>
  <authentication mode="Windows"/>
  <pages>
   <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   </controls>
  </pages>
  <httpHandlers>
   <remove verb="*" path="*.asmx"/>
   <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
  </httpHandlers>
  <httpModules>
   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </httpModules>
 </system.web>
 <system.codedom>
  <compilers>
   <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="WarnAsError" value="false"/>
   </compiler>
   <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="OptionInfer" value="true"/>
    <providerOption name="WarnAsError" value="false"/>
   </compiler>
  </compilers>
 </system.codedom>
 <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
 <system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules>
   <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </modules>
  <handlers>
   <remove name="WebServiceHandlerFactory-Integrated"/>
   <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
   <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </handlers>
 </system.webServer>
 <system.serviceModel>
  <bindings>
   <basicHttpBinding>
    <binding name="RisBasicHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="6553600" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
     <security mode="Transport">
      <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
     </security>
    </binding>
    <binding name="default" sendTimeout="00:10:00" maxBufferSize="655360000" transferMode="Buffered" maxBufferPoolSize="655360000" maxReceivedMessageSize="655360000">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
   </basicHttpBinding>
  </bindings>
  <behaviors>
   <serviceBehaviors>
    <behavior name="Kpmg.Nggc.ServiceImplementation.EngagementEvaluationService_Behavior">
     <serviceDebug includeExceptionDetailInFaults="true"/>
     <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  <services>
   <service behaviorConfiguration="Kpmg.Nggc.ServiceImplementation.EngagementEvaluationService_Behavior" name="Kpmg.Nggc.ServiceImplementation.EngagementEvaluationService">
    <endpoint address="" binding="basicHttpBinding" name="EngagementEvaluationServiceEndPoint" bindingConfiguration="default" bindingNamespace="urn:Kpmg.Nggc.WorkFlow.ServiceContracts" contract="Kpmg.Nggc.ServiceContracts.IEngagementEvaluation"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
  </services>
 </system.serviceModel>
</configuration>

 

Aug 1, 2008 at 6:45 PM

Hi,

I'm not sure if this is causing your issue, but it's worth a shot. I see you're using a custom policy for exception shielding. The implementation of the shielding error handler will run your exception through the configured exception policy, and if no exception is thrown it will try again using the default exception policy. If there is some error in the configuration (as in the Exception Type is not set to throw a new exception, which seems to be the case in your config file) the error handler will try to use the default policy, which is missing in your config, and throw an EHAB exception.

Try again making sure the exception type is set to throw new exception.

Cheers,
Fernando