实现自定义服务行为

时间:2013-03-26 11:32:56

标签: c# wcf

我尝试实现自定义服务行为以从响应消息中获取cookie。我在AfterReceiveRequest方法中创建了一个断点。它永远不会被击中。怎么了 ? 我认为需要为服务注册我的服务行为。怎么样 ?

行为:

public class HttpResponseMessageInspector : BehaviorExtensionElement, IDispatchMessageInspector, IServiceBehavior
{
    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {

        //Here is my breakpoint

        return null;
    }

}


的Web.config

<extensions>
  <behaviorExtensions>
    <add name="HttpResponseMessageInspector" type="MyNamespace.HttpResponseMessageInspector, myassembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  </behaviorExtensions>
</extensions>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <HttpResponseMessageInspector/>
    </behavior>
  </serviceBehaviors>
</behaviors>


服务注册

        RouteTable.Routes.Add(new ServiceRoute("Customers", new NinjectWebServiceHostFactory(), typeof(CustomersService)));
        RouteTable.Routes.Add(new ServiceRoute("Companies", new NinjectWebServiceHostFactory(), typeof(CompaniesService)));

1 个答案:

答案 0 :(得分:0)

我创建了一个实现NinjectWebServiceHostFactory并覆盖CreateServiceHost函数的课程。