2012-08-14 103 views
0

我打算根据不同的合同托管多个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> 
+0

你能后的完整的system.serviceModel部分。可能很容易帮助你 – Rajesh 2012-08-14 14:52:22

+0

@Rajesh:刚刚编辑。这是一个非常基本的,所以我不明白发生了什么 – user1589780 2012-08-14 15:00:14

+0

你可以尝试在你的配置中的serviceHostingEnvironment元素添加multipleSiteBindingsEnabled =“true”,看看它是否得到它的工作。我尝试了相同的示例,它的工作原理 – Rajesh 2012-08-14 15:04:12

回答

1

我真的建议你安装WCF REST Service Template 40和看一看引导。

的Web.config

<standardEndpoints> 
    <webHttpEndpoint> 
    <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
    --> 
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
    </webHttpEndpoint> 
</standardEndpoints> 

的Global.asax

// Edit the base address of Service1 by replacing the "Service1" string below 
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1))); 
+0

如果我的理解正确,那么您没有回答OP的问题,即如何配置由同一个应用程序托管的2个服务。这里是答案:http://stackoverflow.com/a/6772983/548098 – Marshal 2013-02-08 04:49:17