假设有如图环境,内网客户端需要通过一台可以连接外网的路由服务器将数据发送到外网服务器A或B,我需要实现的是,假设将客户端配置为请求地址Address=“net.tcp://192.168.1.199:1211/routingservice/router”时,将数据发送到A服务器,当Address=“net.tcp://192.168.1.199:12110/routingservice/router”时,将数据发送到B服务器,唯一的区别是端口号,通过不同端口发送的请求被转发至相应服务器,调用的都是同一个服务,也就是说服务器A与服务器B上面部署的是2套相同的服务
这里不是做负载均衡,单纯就为实现这个目的,不考虑其他的,中间的路由服务器应该如何配置,使用的是wcf的路由服务,目前仅仅实现了将客户端数据转发,可以访问外网,不知道该怎么配置可以将相应的端口请求发送到不同的服务器(A,B),贴下路由服务的配置文件
<system.serviceModel> <services> <!--ROUTING SERVICE --> <service behaviorConfiguration="routingData" name="System.ServiceModel.Routing.RoutingService"> <endpoint address="net.tcp://192.168.1.199:1211/routingservice/router" binding="netTcpBinding" bindingConfiguration="TcpIDHelperService" name="reqReplyEndpoint" contract="System.ServiceModel.Routing.IRequestReplyRouter" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="routingData"> <serviceMetadata httpGetEnabled="True" httpGetUrl="http://192.168.1.199:508/Routingservice"/> <routing filterTableName="routingTable1" /> </behavior> </serviceBehaviors> </behaviors> <client> <endpoint name="IDHelperService" address="http://192.168.1.199:1113/DataIdentService" bindingConfiguration="IDHelperService" binding="wsHttpBinding" contract="*" /> </client> <!--ROUTING SECTION --> <routing> <filters> <filter name="MatchAllFilter1" filterType="MatchAll" /> </filters> <filterTables> <filterTable name="routingTable1"> <add filterName="MatchAllFilter1" endpointName="IDHelperService" /> </filterTable> </filterTables> </routing> <bindings> <netTcpBinding> <binding name="TcpIDHelperService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:08:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> <reliableSession ordered="false" inactivityTimeout="00:10:00" enabled="true" /> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </netTcpBinding> <wsHttpBinding> <binding name="IDHelperService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" useDefaultWebProxy="false" sendTimeout="00:08:00"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession ordered="false" inactivityTimeout="00:10:00" enabled="true" /> <security mode="None" /> </binding> </wsHttpBinding> </bindings> </system.serviceModel>
这个配置文件是我本机测试用的,所以IP都是同网段,实际上时路由服务在一个双网卡机器上,通过路由服务将内网请求发送到外网服务器
可以自己在appsetting加个config
1 <add key="RouterUrl" port="1211" value="net.tcp://192.168.1.199:1211/routingservice/router"/> 2 3 <add key="RouterUrl" port="12110" value="net.tcp://192.168.1.199:12110/routingservice/router"/>
根据请求端口号匹配config找到对应的服务器,再发出请求。
能详细点么,帮我在上面配置文件的基础上改下,最基础的还是看微软的简单示例,对wcf还是初学
<routing>
<filters>
<filter name="MatchAllFilter1" filterType="EndpointName" filterData="reqReplyEndpoint" />
<filter name="MatchAllFilter2" filterType="EndpointName" filterData="reqReplyEndpointLocal"/>
</filters>
<filterTables>
<filterTable name="routingTable1">
<add filterName="MatchAllFilter1" endpointName="IDHelperService" />
<add filterName="MatchAllFilter2" endpointName="IDHelperServiceLocal" />
</filterTable>
<!--<filterTable name="routingTable2">
<add filterName="MatchAllFilter2" endpointName="IDHelperServiceLocal" />
</filterTable>-->
</filterTables>
</routing>