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 7761533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:09:38+00:00 2026-06-01T14:09:38+00:00

A web service running in IIS but through a factory doesn’t keep up the

  • 0

A web service running in IIS but through a factory doesn’t keep up the original exception thrown.

For example:

My web service has been marked up with FaultContractAttribute like this way:

public interface IMyService
{
    [FaultContract(typeof(MyCustomException))]
    [OperationContract]
    bool IsAuthorized();
}

My web service implementation has throws out a custom exception like this way:

public class MyService : IMyService
{
    public bool IsAuthorized()
    {
        throw new FaultException<MyCustomException>(fault, fr);
    }
}

Then:

  1. If my WCF – NOT using any factory – is similar to <%@ ServiceHost Language="C#" Debug="true" Service="MyService" %>, then on client side I CAN pick up the original exception (MyCustomException)

  2. If my WCF – USING some factory – is similar to <%@ ServiceHost Language="C#" Debug="true" Service="MyService" Factory="MyFactory" %>, then on client side I CAN’T pick up the original exception (MyCustomException) but only SOAP exception (FaultException) with useless general trace & message

Note:

WCF factory MyFactory is implemented with its SERVICE HOST contains a SERVICE BEHAVIOR initiated from IErrorHandler

In this service behavior, method ProvideFault does nothing (I haven’t known how to keep up the original exception by this way)

In summary, I beg answers from expects: How to keep up the original exception (MyCustomException) while using some WCF factory ?
Thanks.

  • 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-01T14:09:39+00:00Added an answer on June 1, 2026 at 2:09 pm

    In my recent project (WCF REST services) I use WebServiceHostFactory and I still was able to achieve this using IErrorHandler. Find below a sample

    I created a class ExceptionInfo that could be serialized and sent back to the client.

    [Serializable]
    public class ExceptionInfo
    {
        public string ExceptionType { get; set; }
        public string ExceptionMessage { get; set; }
        public string StackTrace { get; set; }
    }
    

    And implementing a custom error handler

    [DataContract]
    public class MyCustomServiceErrorHandler : IErrorHandler
    {
        #region IErrorHandler Members
    
        /// <summary>
        /// This method will execute whenever an exception occurs in WCF method execution
        /// </summary>
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var exceptionInfo = new ExceptionInfo();
    
            if (error is MyCustomException)
                exceptionInfo.ExceptionType = error.Type.ToString();;
            else
                exceptionInfo.Type = "Unhandled Exception";
    
            exceptionInfo.ExceptionMessage = error.Message;            
            exceptionInfo.StackTrace = error.StackTrace;
    
            var faultException = new FaultException<ExceptionInfo>(exceptionInfo);
    
            object detail = faultException.GetType().GetProperty("Detail").GetGetMethod().Invoke(faultException, null);
    
            fault = Message.CreateMessage(version, "", detail, new DataContractSerializer(detail.GetType()));
    
            var webBodyFormatMessageProp = new WebBodyFormatMessageProperty(WebContentFormat.Xml);
    
            fault.Properties.Add(WebBodyFormatMessageProperty.Name, webBodyFormatMessageProp);
    
            var httpResponseMessageProp = new HttpResponseMessageProperty();
    
            httpResponseMessageProp.Headers[HttpResponseHeader.ContentType] = "application/xml";
            httpResponseMessageProp.StatusCode = HttpStatusCode.BadRequest;
            httpResponseMessageProp.StatusDescription = exceptionInfo.ExceptionMessage;
    
            fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponseMessageProp);
    
        }
    
        /// <summary>
        /// Performs error related behavior
        /// </summary>
        /// <param name="error">Exception raised by the program</param>
        /// <returns></returns>
        public bool HandleError(Exception error)
        {
            // Returning true indicates that an action(behavior) has been taken (in ProvideFault method) on the exception thrown.
            return true;
        }
    

    Now you can decorate your services using the above handler.

    [ServiceContract]    
    [ServiceErrorBehavior(typeof (MyCustomServiceErrorHandler))]
    public class LoginService : ServiceBase
    {}
    

    On the client side, you can check if the HttpStatusCode of the response != Ok and deserialize the response to ExceptionInfo type and display in a message box or handle per requirement.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that is running on IIS (6 or 7, doesn't
Is it possible to consume a SOAP or REST web service running on IIS
I am running on Windows 7/IIS 7.5, and have a web service set up
I have a WCF RESTful web service (using the webHttpBinding) running under IIS, exposed
I have an echo web service running on lets say http://localhost:8080/axis2/services/Service1 . This service
I have a .NET Web Service running in VS2005 and a client that consumes
I have a .NET 3.5 based web service running at http://localhost/serivce.svc/ . Then I
I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I am trying to access my local database using a web service also running
Currently we got a web service up and running that handles all our C.R.U.D

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.