WCF client with Client Certificate and Basic Authentication

随声附和 提交于 2019-12-11 04:33:31

问题


I need to access web services of one of our partners. Their services are secured with both a Client Certificate and Basic Authentication. I'm using WCF with BasicHttpBinding.

I am able to hook up the cert using Transport level security. I know the cert is working because I'm no longer getting a 403 error, but I am getting a 401 because I can't pass the credentials along with the transport. From what I can see, I can only have one type of transport security scheme.

How can I achieve this?

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

Thanks


回答1:


Did you tried to pass credential at message level. Your config should look like:

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

and then in the code

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


来源:https://stackoverflow.com/questions/8214259/wcf-client-with-client-certificate-and-basic-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!