请问有人做过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是没错的。
我这个总是做不对,谁能帮忙指点一下或者给个例子吗?
之前,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/
好好,谢谢啦,我先看一下
谢谢你,我似乎是搞定了,刚才做的一个小例子(路由就是照这个文档做的)居然路由成功了,开心啊
这件事搞了两天了,终于有点眉目了