【问题标题】:WCF: unsecured or incorrectly secured fault was received from the other partyWCF:从另一方收到不安全或不正确安全的故障
【发布时间】:2012-07-17 07:23:23
【问题描述】:

我创建了一个具有 aspnet 角色和安全性的 wcf 服务。

当我在一个网站上使用它并尝试检查时,使用正确的用户名和密码它可以完美运行,但使用不正确的用户名和密码它会给我一个错误:

从对方收到不安全或不正确安全的故障 派对。故障代码和细节见内部FaultException。

我本来希望得到“访问被拒绝”。

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

更新

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

仍然遇到同样的错误,但没有得到实际的“访问被拒绝”。

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

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();
}

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

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;
        }
    }

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

【问题讨论】:

    标签: wcf


    【解决方案1】:

    您应该使用FaultContracts 来避免此消息。

    【讨论】:

      【解决方案2】:

      我刚遇到这个问题,不得不关闭 WCF 绑定的安全上下文。您需要在客户端和服务中的绑定上关闭它们。

      如果您的 WCF 是 IIS 托管的,那么这里是配置文件:

      <ws2007FederationHttpBinding>
          <binding>
              <security mode="TransportWithMessageCredential">
                  <message establishSecurityContext="false" />
              </security>
          </binding>
      </ws2007FederationHttpBinding>
      

      看到这个帖子: http://stack247.wordpress.com/2013/05/28/an-unsecured-or-incorrectly-secured-fault-was-received-from-the-other-party/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多