WCF:从另一方收到不安全或错误安全的故障 [英] WCF: unsecured or incorrectly secured fault was received from the other party

查看:29
本文介绍了WCF:从另一方收到不安全或错误安全的故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有 aspnet 角色的 wcf 服务 &安全.

I have created one wcf service with aspnet role & security.

当我在一个网站上使用它并尝试使用正确的用户名进行检查时密码它工作完美,但用户名不正确&密码它给了我一个错误:

When I consumed that in one website and try to check that, with correct username & password it works perfect, but with incorrect username & password it gives me an error:

从另一方收到不安全或不正确保护的故障派对.故障代码和详细信息参见内部的FaultException.

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

我本来希望得到访问被拒绝".

I would have expected to get "Access is Denied" instead.

所以,知道为什么吗???

So, Any idea why???

更新

你说得对,我们可以添加 FaultContracts ......但即使我添加了它也会给我同样的错误......此外,我试图检查同一个用户是否为 isinrole ,如果不是,然后外部触发了 FaultException ...

You are right we can add FaultContracts ... but even though I added it gives me same error.. moreover I tried to check the same user isinrole or not if not then externally fired the FaultException...

仍然得到同样的错误,没有得到实际的访问被拒绝".

Still getting the same error not getting the actual "Access is Denied".

只是为了更新您,我已使用 aspnet 表单身份验证来检查凭据 &在角色...代码有点像

Just to update you that I have used aspnet Form Authentication for checking the credential & in role... code is somewhat like

public class SampleService : ISampleService
{
    [PrincipalPermission(SecurityAction.Demand, Role = "admin")]
    public string GetCurrentTime()
    {
        if (!Roles.IsUserInRole(HttpContext.Current.User.Identity.Name, "admin"))
            return DateTime.Now.ToString();
        else
            throw new FaultException("Access is denied");
    }
}

[ServiceContract]
public interface ISampleService
{
    [OperationContract]
    string GetCurrentTime();
}

在客户端,我消费的地方,这个服务......

At the client side, Where i consumed, this service...

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            ChannelFactory<AuthCustWithAspnetRoleService.ISampleService> factory = new ChannelFactory<AuthCustWithAspnetRoleService.ISampleService>("*");
            factory.Credentials.UserName.UserName = txtUserName.Text.Trim(); // "admin"; 
            factory.Credentials.UserName.Password = txtPassword.Text.Trim(); // "admin";
            AuthCustWithAspnetRoleService.ISampleService proxy = factory.CreateChannel();
            lblMessage.Text = proxy.GetCurrentTime();
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
        }
    }

希望这将指导您更多地了解我的代码,并且您可以更详细地帮助我....我不知道为什么其他(我理解这个概念的参考很少)得到访问被拒绝"并且我没有直接从系统中得到这个......

Hope this will guide you more about my code and you may help me in more detail.... I don't know why other (few reference where i understood this concept) got "Access is denied" and I am not directly getting this from system...

推荐答案

你应该使用 FaultContracts 以避免此消息.

You should use FaultContracts to avoid this message.

这篇关于WCF:从另一方收到不安全或错误安全的故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆