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

  • Home
  • SEARCH
  • 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 8873267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:25:21+00:00 2026-06-14T18:25:21+00:00

I have a problem configuring a ServiceBehavior for my WCF service. Some background. Basically

  • 0

I have a problem configuring a ServiceBehavior for my WCF service.

Some background.
Basically I am developing a REST service WCF that is supposed to run on IIS.
I need to be able to log exceptions thrown by the service (I’m using log4net) and return HTTP status codes depending on the type of exception.
I want my service implementation to have a minimum knowledge of WCF related stuff, so I don’t want to convert the exceptions to FaultException everywhere in the service.
So I figured out that adding my own IErrorHandler to the service host would be the best way to do it.

My problem is however that no matter what I try I can’t seem to get the configuration for my custom ServiceBehavior right in Web.config.
Here is the relevant code.

Web config.

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </modules>
</system.webServer>

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="UsingErrorLogBehavior">
        <errorLogBehavior/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior>
        <webHttp/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <extensions>
    <behaviorExtensions>
      <add name="errorLogBehavior"
           type="MyNameSpace.Web.ErrorExtensionElement, MyNameSpace.Web"/>
    </behaviorExtensions>
  </extensions>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <standardEndpoints>
    <webHttpEndpoint>
      <standardEndpoint name="" helpEnabled="true" 
                        automaticFormatSelectionEnabled="false" 
                        defaultOutgoingResponseFormat="Json" 
                        maxReceivedMessageSize="4194304" transferMode="Buffered" />
    </webHttpEndpoint>
  </standardEndpoints>
</system.serviceModel>

ErrorExtensionElement.

namespace MyNameSpace.Web
{
    public class ErrorExtensionElement : BehaviorExtensionElement
    {
        public override Type BehaviorType
        {
            get { return typeof(ErrorServiceBehavior); }
        }

        protected override object CreateBehavior()
        {
            return new ErrorServiceBehavior();
        }
    }
}

ErrorServiceBehavior.

namespace MyNameSpace.Web
{
    public class ErrorServiceBehavior : IServiceBehavior
    {
        public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
            {
                channelDispatcher.ErrorHandlers.Add(new ExceptionModule());
            }
        }

        public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
        }
    }
}

Where ExceptionModule implements IErrorHandler.

  • 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-14T18:25:23+00:00Added an answer on June 14, 2026 at 6:25 pm

    You have a <serviceBehavior> section named “UsingErrorLogBehavior”, but no service configurations are referencing that section. You can either make that section the default service behavior (by not giving it a name, like you have for the endpoint behavior), or add a <service> element for your service which references that behavior:

    <services>
      <service name="YourNamespace.YourServiceName"
               behaviorConfiguration="UsingErrorLogBehavior">
        <endpoint address=""
                  binding="webHttpBinding"
                  contract="YourNamespace.YourContractName" />
      </service>
    </services>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Configuring IIS 6.0 to run an MVC3 application I think I have a configuration
I have a problem configuring multiple hostnames in Composite C1. Background: I have two
I have a WCF 4.0 service hosted in IIS 7.5 on Windows 2008 R2
I have a problem configuring IntelliJ IDEA for developing spring and maven powered application.
I have some problem while configuring symfony project on the production server. When I
I have problem developing with live555. I already build the lib-files and example projects
I'm configuring and testing spring security 3.1.0. I have a user that has ROLE_COMPANY_OWNER.
I have a problem configuring my system for using the NDK over Windows. Those
I have several Maven projects in eclipse that depends on each other. Some of
I have a WCF client that is crashing with the error The EncryptedKey clause

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.