2010-07-19 122 views
0

是否有可能在WCF 4中为REST基础服务使用新的WCF路由服务?我有一些类似于逆向代理的想法。基本上我有一些selfhosted rest基于serivces,我想通过IIS公开与相同的基础URL和端口。路由应该由url的最后部分完成。我是WCF路由服务的绝对新手,所以如果这是一个愚蠢的问题,请原谅我,但我在网上找不到任何有关此信息的信息。.net 4 WCF路由服务+ REST

我已经试过这样的事情(其中serivce1/2是selfhosted服务):

<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是自托管服务的基地址,而不是实际的端点。我可以根据基地址进行路由吗(如果可以休息路由),我是否必须为每个端点添加路由?

+0

我认为这可能会错过WCF路由服务。我将使用像ARR这样的“真正”反向代理。 – Jeldrik 2010-07-26 15:41:51

回答

1

我通过使用反向代理(在我的情况下arr)解决了这个问题。我不知道如果为此目的使用WCF路由服务是可能的,但它可能是一种滥用。

+0

为了详细阐述这条细节,我必须安装ARR扩展,然后在iis中启用代理以允许将URL重写到其他主机,然后在我的wcf路由服务web.config中创建重写规则,以便这两个soap和直接的HTML获取处理有点透明。对于不那么简单的网页内容,可能需要一些出站规则。 – LOAS 2012-08-15 10:18:35

1

路由服务仅适用于SOAP请求。要使用RESTful WCF进行路由,您需要使用类似于MVC路由的System.Web.Routing来设置路由。