WCF,和的WebAPI IIS OWIN综合管线。根据路线跳过OWIN [英] WCF, WebAPI and OWIN IIS integrated pipeline. Skip OWIN based on route

查看:513
本文介绍了WCF,和的WebAPI IIS OWIN综合管线。根据路线跳过OWIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

状况

我有一个使用一个WCF后端Silverlight应用程序。展望未来,我们已经搬到JS客户提供的WebAPI。

I have a Silverlight application that uses a WCF backend. Going forward we have moved to JS clients with WebAPI.

我有一对夫妇的WebAPI控制器的,我想从Silverlight客户端使用,因此让他们承载WCF服务的ASP.Net应用程序中加载。

I have a couple of WebAPI controllers that I would like to use from the Silverlight client and so have them loaded within the ASP.Net application that hosts the WCF services.

该作品从一个所有服务都可以点很好,但授权被多次调用WCF的要求;从OWIN并通过WCF ServiceAuthorizationManager

This works fine from a "all services are available" point of view, however Authorization is being invoked multiple times for WCF calls; from OWIN and through WCF ServiceAuthorizationManager

在WCF的身边,我的ServiceAuthorizationManager实现验证在AuthHeader令牌,然后就是把这个令牌(在System.IdentityModel声明转换的意义上)。在一边的WebAPI我使用 Thinktecture.IdentityModel 提供OWIN中间件做令牌验证和声明转换。

On the WCF side, my ServiceAuthorizationManager implementation validates the token in the AuthHeader and then transforms that token (in the System.IdentityModel Claims Transformation sense). On the WebAPI side I'm using Thinktecture.IdentityModel which provides OWIN Middleware to do token validation and claims transformation .

问题是,在OWIN中间件被调用的所有请求(包括WCF请求)。因此,在WCF请求的情况下,我得到验证和转换执行两次。我不能只删除ServiceAuthorizationManager,让中间件处理它,因为WCF一无所知OWIN和ServiceAuthorizationManager的最后一步是设置操作语境主体(不同于ClaimsPrincipal.Current)。

Problem is, the OWIN middleware gets invoked for all requests (including the WCF requests). So in the case of a WCF request I get validation and transformation executed twice. I can't just remove the ServiceAuthorizationManager and let the middleware handle it, because WCF knows nothing of OWIN and the final step of the ServiceAuthorizationManager is to set the operation context principal (different to ClaimsPrincipal.Current).

有没有人有这样的问题之前,WCF和的WebAPI并肩而坐?将最好的办法是莫名其妙地退出了OWIN管道很早就对WCF调用,如果是这样那怎么做,通过OMC?或者,我可以以某种方式使用IAppBuilder.Map方法只注册API路线令牌验证和转换元件(在这种情况下,任何启动/ API)?

Has anyone had a problem like this before with WCF and WebAPI sitting side by side? Would the best approach be to somehow drop out of the OWIN pipeline very early on for WCF calls and if so how can that be done, through an OMC? Or can I somehow use the IAppBuilder.Map approach to only register the token validation and transformation components for API routes (in this case anything starting /api)?

推荐答案

我已经成功地得到这个工作,通过一<一href=\"http://stackoverflow.com/questions/22215428/run-different-frameworks-side-by-side-with-owin\">Branched管道。

I've managed to get this to work via a Branched Pipeline.

app.MapWhen(c => c.Request.Path.Value.Contains("/api"),
                    subApp =>
                    {
                        subApp.UseJsonWebToken(
                            issuer: clientDetails.Issuer,
                            audience: clientDetails.Audience,
                            signingKey: clientDetails.SigningKey);

                        subApp.UseClaimsTransformation(transformer.Transform);

                        var webApiConfig = WebApiConfig.Configure();
                        webApiConfig.DependencyResolver = StructureMapConfig.HttpDependencyResolver();
                        subApp.UseWebApi(webApiConfig);
                    });

我唯一想知道的是为什么 IAppBuilder.MapWhen 如上的作品,但是当我使用 IAppBuilder.Map 它似乎不工作...

Only thing I'm wondering is why IAppBuilder.MapWhen as above works, but when I use IAppBuilder.Map it doesn't seem to work...

app.Map("/api",
        subApp => ...

这篇关于WCF,和的WebAPI IIS OWIN综合管线。根据路线跳过OWIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆