2010-10-13 47 views
0

我在WCF REST应用程序中遇到了Windows身份验证问题。WCF 4中的Windows用户名其余

使用VS2010,我选择了新建项目> 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 } }; 
} 

我测试它在本地机器上运行成功,那么我将它发布到IIS7 Windows Server 2008上在IIS管理器,我在应用上启用Windows身份验证并禁用所有其他身份验证类型。 我给它自己的应用程序池与集成托管管道模式。

我可以成功地看到它在Windows资源管理器的Win2008机器上运行(HTTP://本地主机/ JobManager /服务1 /)

从另一台机器使用的是IE 7,但是,它提示我两次的用户名/密码,我填写了两次,但第二次收到401错误。通过改变所使用的应用程序池,以一个身份是访问目录服务:(未授权访问由于凭据无效被拒绝。)

回答

0

解决。