WCF端点路由

发布于 2024-09-05 16:58:26 字数 104 浏览 12 评论 0原文

伙计们,如何在不同端点之间路由入站消息。

我需要公开可以接受不同凭据的单个端点。我想,通过拦截传入消息并基于消息头然后将消息转发到适当的端点来解决此问题。

谢谢。

Guys, how to route inbound message between different endpoints.

I need to expose the single endpoint that could accept different credentials. I guess, solve this by intercept the incoming message and based on message header then do forward message to appropriate endpoint.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习惯成性 2024-09-12 16:58:26

基本上,您需要为拦截器创建自定义行为。这个过程相当深入,所以这里有一个链接,而不是我把所有这些都写出来。

http://msdn.microsoft.com/en-us/magazine/cc163302。 aspx

主要步骤是:

创建自定义行为

   public class AuthorizationInterceptorBehavior: IEndpointBehavior, IServiceBehavior
    {
//Code removed
...
}

创建BehaviorExtension:

    public class AuthorizationInterceptorBehaviorExtensionElement : BehaviorExtensionElement
    {
        public override Type BehaviorType
        {
            get
            {
                return typeof(AuthorizationInterceptorBehavior);
            }
        }

        protected override object CreateBehavior()
        {
            return new AuthorizationInterceptorBehavior();
        }
    }
}

然后创建拦截器并将所有代码放入 AfterReceivedRequest 方法中:

    public class AuthorizationInterceptor : IDispatchMessageInspector
    {  //This class implements the IDispatchMessageInspector which provides the basic access to each message when it is received 
        //by the service and before is sent back to the client

        #region IDispatchMessageInspector Members

        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {

//YOUR CODE HERE
...}

然后只需将拦截器添加到配置文件中:

<system.serviceModel>
        <extensions>
            <behaviorExtensions>
                 <add name="authorizationInterceptor" type="YOUR.ASSEMBLY.AuthorizationInterceptorBehaviorExtensionElement, YOUR.ASSEMBLY, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXX" />
            </behaviorExtensions>
        </extensions>
    </extensions>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SomeServiceBehavior">
                    <authorizationInterceptor />
...

如果您需要更多帮助或指导、评论,我会回复您并提供更多详细信息。最困难的部分是处理传入的请求,因为此时它尚未反序列化,因此您必须将其作为 POX(Plain Ol' Xml)进行处理。

Basically you need to create a custom behavior for your interceptor. The process is rather indepth so here's a link, instead of me typing all of this out.

http://msdn.microsoft.com/en-us/magazine/cc163302.aspx

The main steps are:

Create a custom behavior

   public class AuthorizationInterceptorBehavior: IEndpointBehavior, IServiceBehavior
    {
//Code removed
...
}

Create the BehaviorExtension:

    public class AuthorizationInterceptorBehaviorExtensionElement : BehaviorExtensionElement
    {
        public override Type BehaviorType
        {
            get
            {
                return typeof(AuthorizationInterceptorBehavior);
            }
        }

        protected override object CreateBehavior()
        {
            return new AuthorizationInterceptorBehavior();
        }
    }
}

Then create your interceptor and put all of your code in the AfterReceivedRequest method:

    public class AuthorizationInterceptor : IDispatchMessageInspector
    {  //This class implements the IDispatchMessageInspector which provides the basic access to each message when it is received 
        //by the service and before is sent back to the client

        #region IDispatchMessageInspector Members

        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {

//YOUR CODE HERE
...}

Then you just add your interceptor to your config file:

<system.serviceModel>
        <extensions>
            <behaviorExtensions>
                 <add name="authorizationInterceptor" type="YOUR.ASSEMBLY.AuthorizationInterceptorBehaviorExtensionElement, YOUR.ASSEMBLY, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXX" />
            </behaviorExtensions>
        </extensions>
    </extensions>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SomeServiceBehavior">
                    <authorizationInterceptor />
...

If you need more help or guidance, comment and I'll get back to you with more details. The hardest part is working with the incoming request, as it is not deserialized at this point so you have to work with it as POX (Plain Ol' Xml).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文