代码之家  ›  专栏  ›  技术社区  ›  Jeldrik

.net 4 WCF路由服务+REST

wcf
  •  0
  • Jeldrik  · 技术社区  · 16 年前

    是否可以使用WCF 4中新的WCF路由服务来提供基于REST的服务?我有一个类似于反向代理的想法。基本上,我有许多基于rest的自托管服务,我想通过IIS使用相同的基本url和端口公开这些服务。路由应该由url的最后一部分完成。我对WCF路由服务完全陌生,所以如果这是个愚蠢的问题,请原谅我,但是我在网上找不到任何关于这个的信息。

    我尝试过类似的方法(serivce1/2是自托管服务):

    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="RoutingBehavior">
                    <routing routeOnHeadersOnly="false" filterTableName="RoutingTable"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                    <serviceMetadata httpGetEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="RoutingBehavior" name="System.ServiceModel.Routing.RoutingService">
                <endpoint address="myservices" contract="System.ServiceModel.Routing.IRequestReplyRouter" binding="basicHttpBinding"/>
            </service>
        </services>
        <routing>
            <filterTables>
                <filterTable name="RoutingTable">
                    <add filterName="service1Filter" priority="0" endpointName="service1"/>
                    <add filterName="service2Filter" priority="0" endpointName="service2"/>
                </filterTable>
            </filterTables>
            <filters>
                <filter name="service1Filter" filterType="MatchAll"/>
                <filter name="service2Filter" filterType="MatchAll"/>
            </filters>
        </routing>
        <client>
            <endpoint address="http://somehost:8888/test/service1" binding="basicHttpBinding" contract="*" name="service1"/>
            <endpoint address="http://somehost:8732/test/service2" binding="basicHttpBinding" contract="*" name="service2"/>
        </client>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    

    但这似乎行不通。我得到一个端点未找到异常。 http://somehost:8888/test/service1 ist是自托管服务的基址,而不是实际的终结点。我可以基于基址进行路由吗?或者(如果rest路由是可能的)我必须为每个端点添加一个路由吗?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Jeldrik    16 年前

    我通过使用反向代理(在我的例子中是arr)解决了这个问题。我不知道使用WCF路由服务来实现这个目的是否可行,但这可能是一种误用。

        2
  •  1
  •   Tim Glenn    15 年前

    路由服务仅可用于SOAP请求。要将路由与RESTful WCF结合使用,您需要使用System.Web.routing(类似于MVC路由)设置路由。

    推荐文章