如何在.NET 3.5中调用需要WCF授权的asmx服务

时间:2012-10-08 19:13:23

标签: c# .net wcf web-services .net-3.5

如何从.NET 3.5中的WCF调用需要Windows身份授权的asmx服务?我们仅限于.NET 3.5框架。我有凭据,但不知道如何在C#代码中实现它。

1 个答案:

答案 0 :(得分:0)

http://msdn.microsoft.com/en-us/library/ff406125有一个身份验证示例。在此网址中,按以下方式执行:

public decimal ReportSales()
{
    var currentUser = new WindowsPrincipal((WindowsIdentity)
    System.Threading.Thread.CurrentPrincipal.Identity);
    if (currentUser.IsInRole(WindowsBuiltInRole.BackupOperator))
    {
        return 10000M;
    }
    else
    {
       return -1M;
    }
 }

还有http://haacked.com/archive/2011/10/19/implementing-an-authorization-attribute-for-wcf-web-api.aspx

中描述的编译器属性的替代方法

对于.net的更高版本,WIF将是最佳选择。

我希望这会有所帮助......