【问题标题】:Route to different services based on URL template根据 URL 模板路由到不同的服务
【发布时间】:2017-01-27 10:50:39
【问题描述】:

我正在开发向后兼容项目。其中,WCF 服务支持 OData v1-v3。我正在构建支持 OData v4 的 ASP .NET Web API

我必须在这里调用它们:
http://localhost:17505/api/v4/Products 应该调用 ASP .NET Web API 服务。 http://localhost:17505/api/v3/Products 应该调用 WCF 服务

路由应该在哪里进行?

【问题讨论】:

    标签: c# asp.net web-services wcf odata


    【解决方案1】:

    我终于找到并实施了答案。似乎http.sys 处理了我们需要的一切。只有路由模板应该不同。

    拥有initiateApis 方法,它调用WebAPI 和WCF 类的Start 方法,参数为uri。

    在 WebAPI 类中 - WebApi.cs

    WebApp.Start<WebApi>(uri);
    

    在 WCF 类中 - WcfService.cs

    _serviceHost = new DataServiceHost(typeof(WcfService), new Uri[0]);
    _serviceHost.AddServiceEndpoint(typeof(IRequestHandler), httpBinding, uri);
    

    所以每当传递 url,

    WebApi.Start("http://localhost:17505/api/v4/");
    WcfService.Start("http://localhost:17505/api/v3/");
    

    快乐编码:)

    【讨论】:

      猜你喜欢
      • 2018-07-28
      • 2013-11-27
      • 2022-01-20
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2013-07-23
      • 1970-01-01
      相关资源
      最近更新 更多