WCF REST アプリでの Windows 認証に問題があります。
VS2010 を使用して、[新しいプロジェクト] > [WCF REST サービス アプリケーション] を選択しました。
Windows 認証を保証し、匿名ユーザーを拒否するように web.config を変更しました。
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
</system.web>
応答でユーザー名を返すように Service1.cs を変更しました。
[WebGet(UriTemplate = "",
RequestFormat= WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Bare)]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
string fullID = ServiceSecurityContext.Current.WindowsIdentity.Name;
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello " + fullID } };
}
ローカル マシンで正常に動作することをテストしてから、Windows Server 2008 上の IIS7 に発行します。IIS マネージャーで、アプリで Windows 認証を有効にし、他のすべての認証タイプを無効にします。マネージド パイプライン モードが統合された独自のアプリケーション プールを提供します。
Win2008 マシン (http://localhost/JobManager/Service1/) で実行されている Windows エクスプローラーで正常に表示されます。
別のマシンから IE 7 を使用すると、ユーザー名とパスワードの入力を 2 回求められます。2 回入力しますが、2 回目は 401 エラーが発生します。(不正: 認証情報が無効なため、アクセスが拒否されました。)