WCF 4 Rest中的Windows用户名

WCF 4 Rest中的Windows用户名,wcf,authentication,wcf-rest,Wcf,Authentication,Wcf Rest,我在WCF REST应用程序中使用Windows身份验证时遇到困难 使用VS2010,我选择了New Project>WCF REST服务应用程序 我修改了web.config以确保windows身份验证并拒绝匿名用户 <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Windows" /> <authori

我在WCF REST应用程序中使用Windows身份验证时遇到困难

使用VS2010,我选择了New Project>WCF REST服务应用程序

我修改了web.config以确保windows身份验证并拒绝匿名用户

<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 } };
}
[WebGet(UriTemplate=“”,
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Bare)]
公共列表GetCollection()
{
//TODO:替换当前实现以返回SampleItem实例的集合
WebOperationContext.Current.OutgoingResponse.ContentType=“text/plain”;
字符串fullID=ServiceSecurityContext.Current.WindowsIdentity.Name;
return new List(){new SampleItem(){Id=1,StringValue=“Hello”+fullID}};
}
我在本地机器上成功地测试了它,然后将它发布到Windows Server 2008上的IIS7。在IIS管理器中,我在应用程序上启用Windows身份验证,并禁用所有其他身份验证类型。 我给它自己的应用程序池提供了集成的托管管道模式

我可以在Win2008计算机上运行的windows资源管理器中成功地看到它(http://localhost/JobManager/Service1/)


然而,使用另一台机器上的IE7,它两次提示我输入用户名/密码,我填写了两次,但第二次出现401错误。(未经授权:由于凭据无效,访问被拒绝。)

通过将应用程序池使用的标识更改为可以访问目录服务的标识来解决