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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:54:54+00:00 2026-06-14T03:54:54+00:00

In my rest based WCF service I would like to throw a custom fault

  • 0

In my rest based WCF service I would like to throw a custom fault exception and use XML Serializer to serialize the results as I have a specific XML output format to use.

I have followed online examples exactly but after the code throws an exception I don’t get an xml formatted response. Instead I get an XML tag with a load of html inside in what appears to be a standard response from the server entitled Request Error. The text I get is (html tags):

The server encountered an error processing the request. The exception message is 'Error 123'. See server logs for more details. The exception stack trace is:
at CSW.Services.CheckForCatalogueFaults(String request, String service) in C:\netDev\CatalogueService\CatalogueService\Services.svc.cs:line 64
at CSW.Services.GetCapabilities(String request, String version, String service) in C:\netDev\CatalogueService\CatalogueService\Services.svc.cs:line 69
at SyncInvokeGetCapabilities(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

I have the following settings and classes.

Service:

[OperationContract]
        [XmlSerializerFormat(SupportFaults = true)]
        [FaultContract(typeof(CatalogueFaultContract))]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/csw?REQUEST={request}&VERSION={version}&SERVICE={service}")]
        Capability GetCapabilities(string request,string version, string service);

..one of my error checking conditions in Services implementation…

 if (string.IsNullOrEmpty(request))
            {
                cswFault.Exception = new CswException("MissingParameterValue", "request");
                cswFault.ErrorMsg = "Error";
                     throw new FaultException<CatalogueFaultContract>(cswFault);
            }

My Custom FaultException class:

[XmlRoot(ElementName = "ExceptionReport",Namespace="http://www.opengis.net/ows")]
    public class CatalogueFaultContract 
    {
        [XmlNamespaceDeclarations]
        public XmlSerializerNamespaces Ns;

        [XmlAttribute(AttributeName = "Version")]
        public string Version = "1.0.0";

        [XmlElement(Namespace = "http://www.opengis.net/ows")]
        public CswException Exception { get; set; }

        [XmlAttribute(Namespace = XmlSchema.Namespace, AttributeName = "schemaLocation")]
        public string xsiSchemaLocation = "http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd";

        [XmlIgnore]
        public string ErrorCode { get; set; }
        [XmlIgnore]
        public string ErrorMsg { get; set; }

        public CatalogueFaultContract()
        {}


        public CatalogueFaultContract(string errorCode,string locator)
        {

            Ns = new XmlSerializerNamespaces();
            Ns.Add("", "");
            Ns.Add("ows", "http://www.opengis.net/ows");

            Exception=new CswException(errorCode,locator);

        }
    }

I can’t figure out why it is not displaying the serialized fault class… unless it can’t serialize it properly? Have tried with a very simple class but get same response.

  • 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-14T03:54:55+00:00Added an answer on June 14, 2026 at 3:54 am

    Answer: use a WebFaultException class instead…………..

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

Sidebar

Related Questions

If i implement a REST based WCF service, then as a Request i will
I am trying to build a REST & json based WCF service that takes
I have a REST service that I would like to require client certificates. The
I have a self-hosted WCF REST service based on the WebHttpBinding. One of the
I have a WCF REST service that exposes a couple dozen objects and based
I am writing an application that is consuming an in-house WCF-based REST service and
What are the prerequisites (or steps) to host a WCF REST based service on
We are working on developing a REST based WCF service. I was wondering if
I've got a WCF REST Service which I'd like to unit test. i.e -
In a REST WCF Service, is there a way to create a custom WebFaultException?

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.