我尝试实现自定义服务行为以从响应消息中获取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)));
答案 0 :(得分:0)
我创建了一个实现NinjectWebServiceHostFactory
并覆盖CreateServiceHost
函数的课程。