クラス GreetService のメソッドを公開する WCF REST サービスがあります。
[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)));
これをビジュアル スタジオから直接実行すると、UriTemplate を利用して、 http://localhost:5432/GreetService/greet/JohnDoeへの GET 呼び出しを使用してこのメソッドを呼び出すことができ ます。
ただし、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を呼び出すことはできませんが、指定したのでできると期待していましたIIS7 でホストする前に、対応する web.config ファイル内の空の相対エンドポイント アドレス。
WebGetAttribute が IIS で機能しない理由はありますか? または、私が間違っていることは他にありますか?
編集:これは、IIS が使用するディレクトリにある web.config ファイルの ServiceModel 部分です。
<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>