【发布时间】:2020-04-15 12:22:57
【问题描述】:
我正在开发一个客户端来使用网络服务。端点是 HTTPS。我在尝试登录时收到此异常。为什么?
这是方法
BasicHttpsBinding binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
var ea = new EndpointAddress(new Uri($@"https://endpoint"));
WSPDDClient client = new WSPDDClient(binding, ea);
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "certificatename");
WSPDD.login login1 = new WSPDD.login()
{
login1="username",
password="password"
};
try
{
client.Open();
WSPDD.loginResponse resLogin = client.login(login1);
if (resLogin.@return.success)
{
}
else
{
Debug.WriteLine("Err {0}", resLogin.@return.error);
}
}
catch(Exception ex)
{
Debug.WriteLine("Err {0}", ex);
}
这是 web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WSPDDBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://endpoint"
binding="basicHttpBinding" bindingConfiguration="WSPDDBinding"
contract="WSPDD" name="WSPDDPort" />
</client>
例外是:
HTTP 请求未使用“匿名”客户端身份验证方案授权。从服务器收到的身份验证标头:'Mutual SSL realm = \"WSO2 API Manager \",error = \"invalid token \",error_description = \"The access token expired \"'。 "
例外是在
WSPDD.loginResponse resLogin = client.login(login1);
【问题讨论】:
标签: c# wcf https client wcf-client