我打算根据不同的合同托管多个RESTful服务。有很多类似的问题,但我的web.config文件看起来不同,我不知道为什么。如何正确配置WCF REST服务端点?
这里是我的web.config文件的一部分:
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name=""
helpEnabled="true"
automaticFormatSelectionEnabled="true">
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
这里是我的web应用程序我的服务宣言:
RouteTable.Routes.Add(new ServiceRoute("bob/chocolate", new WebServiceHostFactory(), typeof(RESTchocolate)));
RouteTable.Routes.Add(new ServiceRoute("bob/vanilla", new WebServiceHostFactory(), typeof(RESTvanilla)));
只有第一个途径似乎是工作(使用测试不错的“bob/chocolate/help”终结点功能,列出了可用的方法),这并不意外,但我该如何修改我的web.config文件?你们有没有人知道如何做到这一点?我需要修改其他东西吗?
对于那些想知道的,我的合同是有效的。
如果我尝试访问浏览器中的第二个端点,我会在一个漂亮的.NET显示中看到“Endpoint not found”。
编辑:
添加以下节点,以我的配置文件...
<services>
<service name="chocolate">
<endpoint address="bob/chocolate" binding="basicHttpBinding" name="chocolate" contract="RESTapi.IRESTchocolate" />
</service>
<service name="vanilla">
<endpoint address="bob/vanilla" binding="basicHttpBinding" name="vanilla" contract="RESTapi.IRESTvanilla" />
</service>
</services>
,但我得到了相同的行为。问题仍然是这里
编辑:这里是我的完整的配置文件的要求(无节点以上):
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="None"></authentication>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
你能后的完整的system.serviceModel部分。可能很容易帮助你 – Rajesh 2012-08-14 14:52:22
@Rajesh:刚刚编辑。这是一个非常基本的,所以我不明白发生了什么 – user1589780 2012-08-14 15:00:14
你可以尝试在你的配置中的serviceHostingEnvironment元素添加multipleSiteBindingsEnabled =“true”,看看它是否得到它的工作。我尝试了相同的示例,它的工作原理 – Rajesh 2012-08-14 15:04:12