首页 新闻 搜索 专区 学院

有人做过RESTful WCF的路由服务吗?

0
悬赏园豆:30 [已解决问题] 解决于 2014-12-03 08:16

请问有人做过RESTful WCF的路由服务吗?

我的路由服务的配置:

<system.serviceModel>
<services>
<service behaviorConfiguration="routingData"
name="System.ServiceModel.Routing.RoutingService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:11112"/>
</baseAddresses>
</host>
<endpoint address="hellorouter"
binding="basicHttpBinding"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />
<endpoint address="hellorouter_rest"
binding="webHttpBinding"
behaviorConfiguration="RestEndPointCfg"
bindingConfiguration="webBindingHello"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="routingData">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<routing filterTableName="routingTable" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RestEndPointCfg">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding >
<binding name="webBindingHello"></binding>
</webHttpBinding>
</bindings>
<client>
<endpoint name="HelloService" address="http://localhost:11113/hello" binding="basicHttpBinding" contract="*" />
<endpoint name="RestHelloService" address="http://localhost:11113/hello/rest" binding="webHttpBinding" contract="*" />
</client>

<routing>
<filters>
<filter name="MatchAllFilter1" filterType="EndpointAddress" filterData="http://localhost:11112/hellorouter" />
<filter name="MatchAllFilter2" filterType="PrefixEndpointAddress" filterData="http://localhost:11112/hellorouter_rest" />
</filters>
<filterTables>
<filterTable name="routingTable">
<add filterName="MatchAllFilter1" endpointName="HelloService" />
<add filterName="MatchAllFilter2" endpointName="RestHelloService" />
</filterTable>
</filterTables>
</routing>
</system.serviceModel>

客户端调用:

WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/json");
client.Headers.Add("ContentLength", requestData.Length.ToString());
byte[] responseData = client.UploadData("http://localhost:11112/hellorouter_rest/Say", "POST", requestData);
string result = Encoding.GetEncoding("UTF-8").GetString(responseData);
Console.WriteLine(result);

真正的服务地址是http://localhost:11113/hello/rest,service部分就不写了。

路由服务是http://localhost:11112/hellorouter_rest,客户端调用的是Say方法,所以调用地址是:http://localhost:11112/hellorouter_rest/Say,调用结果是:远程服务器返回错误: (404) 未找到,就是说我的http://localhost:11112/hellorouter_rest/Say这个地址是错的,但我不知道正确的该怎么写啊?

代码的逻辑方面没啥大问题,就是配置有错,如果不通过路由服务,我客户端直接调http://localhost:11113/hello/rest/Say是没错的。

 

我这个总是做不对,谁能帮忙指点一下或者给个例子吗?

问题补充:

发了好多遍才发出去,总说怀疑我的帖子有广告,我吧http换成全角,才发出去:)

暗夜娜姐的主页 暗夜娜姐 | 初学一级 | 园豆:84
提问于:2014-11-02 17:31
< >
分享
最佳答案
0

之前,WCF Routing Service 是不支持 RESTful Service 的,现在的最新版版,我还没看过,你可以了解下,如果仍然不支持,那么你可以考虑此方案:http://blog.kloud.com.au/2012/11/09/build-a-restful-router-using-wcf-browse-azure-table-storage-with-excel/

收获园豆:30
Launcher | 高人七级 |园豆:45045 | 2014-11-03 09:31

好好,谢谢啦,我先看一下

暗夜娜姐 | 园豆:84 (初学一级) | 2014-11-03 09:41

谢谢你,我似乎是搞定了,刚才做的一个小例子(路由就是照这个文档做的)居然路由成功了,开心啊

暗夜娜姐 | 园豆:84 (初学一级) | 2014-11-05 11:10

这件事搞了两天了,终于有点眉目了

暗夜娜姐 | 园豆:84 (初学一级) | 2014-11-05 11:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册