Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:09:29+00:00 2026-06-13T09:09:29+00:00

Let’s say I have the following request object: [DataContract] public class MyContract { [DataMember]

  • 0

Let’s say I have the following request object:

[DataContract]
public class MyContract {
    [DataMember]
    public Guid Token { get; set; }
}

And a WCF service definition as follows:

[ServiceContract]
public interface IMyService {
    [OperationContract]
    bool Validate(MyContract request);
}

If I send the following to the operation, I get the desired response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esi="http://mynamespace.com/" xmlns:con="http://mynamespace.com">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body>
      <esi:Validate>
         <esi:Token>9192ef6a-819f-4a8a-8fde-4125999e33dc</esi:Token>
      </esi:Validate>
   </soapenv:Body>
</soapenv:Envelope>

If I send an invalid Guid (this occurs with any type), I get the following response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
         <faultstring xml:lang="en-GB">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.</faultstring>
      </s:Fault>
   </s:Body>
</s:Envelope>

Which is all well and good, but not really enough information for my consumers, considering my service knows exactly what’s wrong with the data.

I can expose the full exception with the <serviceDebug includeExceptionDetailInFaults="true"/> web config setting, but that’s TOO MUCH information for my consumers! I would rather customise the error at the code level, but I’m not sure how I can attach to the deserializer? I know how to deal with custom SOAP faults and FaultContracts, but this seems to be at a lower level – I need to intercept the incoming message before it hits the CLR methods, somehow? Is there a way to do this that I’m not aware of?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:09:30+00:00Added an answer on June 13, 2026 at 9:09 am

    The deserializer is on the IDispatchMessageFormatter

    public class MyFormatter : IDispatchMessageFormatter
    {
        readonly IDispatchMessageFormatter _originalFormatter;
    
        public MyFormatter(IDispatchMessageFormatter originalFormatter)
        {
          _originalFormatter = originalFormatter;
        }
    
        public void DeserializeRequest(Message message, object[] parameters)
        {
            try
            {
                _originalFormatter.DeserializeRequest(message, parameters);
            }
            catch(Exception ex)
            {
                //throw custom fault here
            }
        }
    
        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
        {
            return _originalFormatter.SerializeReply(messageVersion, parameters, result);
        }
    

    You can hook this up via an OperationBehavior:

    public class MyOperationBehavior : IOperationBehavior
    {
        public void Validate(OperationDescription operationDescription) { }
        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            dispatchOperation.Formatter = new MyFormatter(dispatchOperation.Formatter);
        }
        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { }
        public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters) { }
    
    }
    

    Hook up the OperationBehavior to your service operations via an attribute.

    If you need to use configuration, attach them via a ServiceBehavior or EndpointBehavior


    You can catch errors and handle them by implementing the IErrorHandler.

    Try attaching this to a service behavior:

    public class ServiceExceptionBehaviour : BehaviorExtensionElement, IServiceBehavior, IErrorHandler
    {
       //...
       //implement all required methods
       //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say you have a class called Customer, which contains the following fields: UserName
Let me explain best with an example. Say you have node class that can
Let's say you have a class and you create a HashSet which can store
Let's say I have a (trivial) class, which is move-constructible and move-assignable but not
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let say I have the following desire, to simplify the IConvertible's to allow me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.