English 中文(简体)
WCF 路线服务 —— 此前不再要求
原标题:WCF routing service IClientMessageInspector --> BeforeSendRequest not calling

I need to add the HTTP header for each message in WCF Routing service before sending to back end service. I have implemented the below class. However when I debug "BeforeSendRequest " is not called hence HTTP header ic not added.

我注意到,“接收请求”是被称作的,我增加了吉大港定居地的头盔,但发现头盔不是向后站服务器发送。

然而,我需要补充的是,在“要求”时,这并不是触发的。

public class RouterMessageLogger : BehaviorExtensionElement, IClientMessageInspector, IEndpointBehavior, IDispatchMessageInspector 
{    

    public override Type BehaviorType
    { 
        get 
        {
            return typeof(RouterMessageLogger);
        } 
    }        
    protected override object CreateBehavior()
    {
        return new RouterMessageLogger();
    }


    #region IClientMessageInspector Members
    **public object BeforeSendRequest(ref Message request, IClientChannel channel) 
    {
        Message MyMsg = request;
        this.AddHTTPHeader(ref request);
        //_Logging.LogMessage("Routing message to service");
        return null;
    }**
    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        Message MyMsg = reply;
        //_Logging.LogMessage("Response from service received");
    }    
    #endregion    

    #region IDispatchMessageInspector Members    
    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {
        Message MyMsg = request;

        this.AddHTTPHeader( ref request);
        //_Logging.LogMessage("Message received from client"); 
        return request;
    }    
    public void BeforeSendReply(ref Message reply, object correlationState)
    {
        Message MyMsg = reply;
        this.AddHTTPHeader(ref reply);
        //_Logging.LogMessage("Sending response to client");
    }    
    #endregion

    #region IEndpointBehavior Members    
    public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
        bindingParameters.Add(this); 
        //return;
    }    
    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {        
        clientRuntime.MessageInspectors.Add(this);
        clientRuntime.CallbackDispatchRuntime.ImpersonateCallerForAllOperations = true;

    }    
    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {        
        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
    }    
    public void Validate(ServiceEndpoint endpoint)
    {
        return;
    }
}
问题回答

这个问题的解决办法如下。

您即将到来的服务或终点的SAPProcessingBehavior(在您的行程中)。 http://msdn.microsoft.com/en-us/library/ee816919.aspx”rel=“nofollow”http://msdn.microsoft.com/en-us/library/ee816919.aspx





相关问题
Rails: Proxy Pass?

I ve got a web-app that I want to migrate to Rails, which is currently just plain HTML with an Apache proxy to another server, running a custom database/webserver that serves the site s dynamic ...

MVC routing is not handling one of my directories

I m using ASP.NET MVC with IIS 7.0. I ve got 404 errors hooked up fine through my Application_Error override. In addition to "Controllers", "Models", "Helpers" etc. I have a directory called Files ...

Ruby on Rails conditional routing

I have a site listing many jobs, but I also want each account to be able to access its jobs in one place. Thus, I am using these routes: map.resources :jobs map.resource :account, :has_many => :...

Clean URL s using OpenCart s router class

How do you write clean URL s in OpenCart using their built in Router class? Here is my .htaccess file: RewriteEngine On RewriteRule ^(system) - [F,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...

subdomain routing to multiple controller issue

I have a site: www.mydomain.com where we have administrative controls hidden away from normal customer view. I would like to only access the administrative features under a subdomain such as admin....

Can controller names in RESTful routes be optional?

With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/...

Help with rails routes

Im having a little trouble setting up routes. I have a users controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be usuarios ...

热门标签