2012-08-14 109 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