WCF客户端具有客户端证书和基本身份验证

时间:2011-11-21 15:35:25

标签: c# wcf-security basic-authentication basichttpbinding client-certificates

我需要访问其中一个合作伙伴的网络服务。 他们的服务使用客户端证书和基本身份验证进行保护。 我正在使用WCF和BasicHttpBinding。

我可以使用传输级安全性来连接证书。 我知道证书正在运行,因为我不再收到403错误,但我得到的是401,因为我无法将凭据与传输一起传递。 从我所看到的,我只能有一种类型的传输安全方案。

我怎样才能做到这一点?

<security mode="Transport">
     <transport type="Certificate" />
     <transport type="Basic" />
</security>

由于

1 个答案:

答案 0 :(得分:4)

您是否尝试在邮件级别传递凭据? 您的配置应如下所示:

<security mode="Transport">
        <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

然后在代码中

 WebServiceProxy objClient = new WebServiceProxy ();
  objclient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "clientCert");
 objClient.ClientCredentials.UserName.UserName = "username";
 objClient.ClientCredentials.UserName.Password = "Password";