託管WCF服務我有一個WCF REST服務暴露在課堂GreetService的方法:REST方法不能訪問時,在IIS
[ServiceContract]
public class GreetService
{
[WebGet(UriTemplate = "greet/{name}")]
public String GreetName(string name)
{
return "Hello " + name;
}
}
而且,我註冊在Global.asax中的路由:
RouteTable.Routes.Add(new ServiceRoute("GreetService", new WebServiceHostFactory(), typeof(GreetService)));
現在,當我運行這個直接從Visual Studio中,我能夠利用UriTemplate和調用使用GET調用這個方法來 http://localhost:5432/GreetService/greet/JohnDoe
不過,通過創建它Greet.svc文件部署這IIS7後,我觀察以下行爲:
- 我可以調用http://localhost:5432/Greet.svc和它說,服務已創建
- 我可以點wcftestclient到http://localhost:5432/Greet.svc?wsdl生成)一個測試客戶端,其可以調用GreetName(直接
- 然而,我不能叫http://localhost:5432/Greet.svc/GreetService/greet/JohnDoe也不http://localhost:5432/Greet.svc/greet/JohnDoe雖然我期望能夠自我在相應web.config文件指定一個空的相對端點地址在IIS7中託管它之前。
任何想法爲什麼WebGetAttribute不能在IIS中工作?還是有什麼我做錯了?
編輯: 這是我的web.config文件的ServiceModel一部分駐留在IIS使用的目錄:
<system.serviceModel>
<!-- <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> -->
<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>
</system.serviceModel>
編輯2:爲了完整性這裏是我的全部web.config文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler,
System.Web, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
<system.serviceModel>
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>-->
<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>
</system.serviceModel>
</configuration>
請張貼的web.config,至少system.servicemodel部分:) – 2010-07-13 16:19:54
感謝你的努力,我應該這樣做擺在首位。我正在使用StandardEndpoint,不確定這在行爲方面意味着什麼。 – Masterfu 2010-07-14 19:35:23
你如何特別部署到IIS?你是否將項目的「Web」選項卡更改爲IIS vdir?你真的有IIS偵聽端口5432? (根據您在部署到IIS後嘗試的內容)。正常情況下,在切換到Web選項卡中的本地IIS後,您將打開http:// localhost/MyProject/GreetService/greet/JohnDoe或類似 – 2010-07-15 02:50:54