Exception from wcf webservice not working as it should

Topics: Exception Handling Application Block
May 7, 2007 at 8:41 PM
Hi.

I have a problem with the wcf exception block. The client gives me this error:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
instead of throwing a an FaultException<ServiceFault>. I'm not sure what I'm doing wrong and I dont think there´s contractmismatch because service works fine when it doesnt throw a exception.

I've configured the Exception handling tag in the webconfig like this
<exceptionHandling>
<exceptionPolicies>
<add name="WCF Exception Shielding">
<exceptionTypes>
<add type="System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException" name="InvalidOperationException">
<exceptionHandlers>
<add faultContractType="MyNamespace.Services.ServiceContracts.ServiceFault, ServiceContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
exceptionMessage="" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="DefaultFaultContract Handler">
<mappings>
<add source="{Message}" name="MessageText" />
<add source="{Guid}" name="Id" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>

Here is the serviceFault class:

namespace Landsbanki.Services.ServiceContracts
{
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; }
}
}
}

The contract interface is under the same namspace and it has the ExceptionShielding attribute.
Does anyone know whats worng with this or why I'm not getting the exception block to work properly?
Aug 2, 2007 at 8:27 AM
Are you sure you've used the FaultContractAttribute on the operation, and set it to ServiceFault? If you haven't, the WCF Exception handler will send back the response action as the incoming request action, and if you're using a binding that uses Security, you'll see an error. Use service diagnostics to check the exact error on the client. Also remember that the WCF Exception Handler will not work correctly if includeExceptionDetails is set to True.
Aug 4, 2007 at 1:09 PM
Hi

I got it to work finally. I made a new project for the faultcontracts and that seemed to do the trick. I'm not sure why the other didnt work, but its working now.