Pregunta

So I stand up a few ServiceHosts with the Spring.net proxy objects and all is well. I now want to add a custom error handler in xml. I can stand it up in spring if necessary, but I have no clue how to do this. My app.config is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
    </sectionGroup>
    <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler"/>
  </configSections>

  <log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value="logs/crowbarserver.log"/>
      <maximumFileSize value="100KB"/>
      <maxSizeRollBackups value="20"/>
      <appendToFile value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger %ndc (%file:%line) - %message%newline"/>
      </layout>
    </appender>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="RollingFile"/>
    </root>
  </log4net>

  <spring>
    <context>
      <resource uri="config://spring/objects"/>
    </context>
    <objects>
      <object id="passDatabase" type="CrowbarCommon.Database.stub.StubDatabase, CrowbarCommon" autowire="autodetect" />
      <object id="authDatabase" type="CrowbarCommon.Database.stub.StubDatabase, CrowbarCommon" autowire="autodetect" />

      <object id="basicAuthManager" type="CrowbarCommon.Domain.AuthManagerImplementations.BasicAuthManager" >
        <constructor-arg name="passwordDatabase" ref="passDatabase"/>
        <constructor-arg name="authenticatedPlayerDatabase" ref="authDatabase"/>
      </object>

      <object id="serverService" singleton="false" type="DedicatedServer.ServerService, DedicatedServer" >
        <constructor-arg name="authManager" ref="basicAuthManager"/>
      </object>

      <object id="ServerServiceManager" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
        <property name="TargetName" value="serverService" />
      </object>

      <object id="playerService" singleton="false" type="DedicatedServer.PlayerService, DedicatedServer" >
        <constructor-arg name="authManager" ref="basicAuthManager"/>
      </object>    

      <object id="PlayerServiceManager" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
        <property name="TargetName" value="playerService" />
      </object>

      <object id="restService" singleton="false" type="RESTService.RestService, RESTService" />

      <object id="RESTServiceManager" type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
        <property name="TargetName" value="restService" />
      </object>
    </objects>
  </spring>

  <databaseSettings>
    <add key="db.user" value="username" />
    <add key="db.password" value="password" />
    <add key="db.dataSource" value="server,port" />
    <add key="db.database" value="dbname" />
  </databaseSettings>

  <system.serviceModel>
    <services>
      <service name="serverService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="CrowbarCommon.IServerService" behaviorConfiguration="web"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/server/"/>
          </baseAddresses>
        </host>
      </service>
      <service name="playerService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="CrowbarCommon.IPlayerService" behaviorConfiguration="web"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/player/"/>
          </baseAddresses>
        </host>
      </service>
      <service name="restService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="CrowbarCommon.IRestService" behaviorConfiguration="web"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/rest/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I have found how to do it in code:

public class MyBehavior : IEndpointBehavior
{
    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new MyErrorHandler());
    }
}

Can anyone help me?

¿Fue útil?

Solución

Never mind, I answered my own question.

THIS article was most illuminating and gave a full example. All you need to do is follow the examples section there.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top