How to setup up web.config for WCF IErrorhandler

后端 未结 2 1600
萌比男神i
萌比男神i 2021-02-08 00:36

Can\'t integrate IErrorHandler into my project with the correct web.config

I have a successfully working WCF that is being consumed by webclients in .net 4 but when tryi

相关标签:
2条回答
  • It's a bit late, but for other users here is a better approach (in my opinion) and the code above only has to be changed a little bit

    You can change:

        public class WcfErrorServiceBehaviour : IServiceBehavior
    

    to:

        public class WcfErrorServiceBehaviourAttribute : Attribute, IServiceBehavior
    

    Now you can use this as an attribute for your service-class like this:

        [WcfErrorServiceBehaviour]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,
                         ConcurrencyMode = ConcurrencyMode.Multiple)]
        public class MXServiceCommands : IMXServiceCommands
        {
        }
    

    Hope this helps some others.

    0 讨论(0)
  • 2021-02-08 01:22
    <system.serviceModel>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="true" />
            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
            <serviceDebug includeExceptionDetailInFaults="true" />
            <errorHandler/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      <extensions>
        <behaviorExtensions>
          <add name="errorHandler" type="CustomerWcfService.WcfErrorHandlerBehaviour, CustomerWcfService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        </behaviorExtensions>
      </extensions>
    </system.serviceModel>
    

    And then apply your behavior to the service you want it to be applied to.

    Edit :

    sorry for the miss, but you actually need to remove any line-break and any additional white space in the type name in the extension definition (old WCF bug which force you to use the fully qualified name string in extension type declaration).

    0 讨论(0)
提交回复
热议问题