我正在测试我创建的WCF Web服务的早期版本.在客户端,当我使用VS来"添加服务引用"时,一切正常.
但是当我尝试使用该服务时,我得到错误,
Run Code Online (Sandbox Code Playgroud)Could not establish trust relationship for the SSL/TLS secure channel with authority **
星号代表服务器的IP地址.
无论如何在服务器上有一个安全证书,但它只是为了测试自己生成的,所以我暂时不担心证书错误.
在客户端,已经为我生成了app.config,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="BindingName" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="***************"
binding="wsHttpBinding" bindingConfiguration="BindingName"
contract="***************" name="BindingName">
<identity>
<servicePrincipalName value="***************" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
那么我需要更改哪些设置才能暂时忽略证书错误?
Mic*_*ana 27
将CertificatePolicy PRIOR设置为在客户端上初始化WCF服务.这是如何(只需调用一次SetCertificatePolicy()方法)
/// <summary>
/// Sets the cert policy.
/// </summary>
private static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
}
/// <summary>
/// Certificate validation callback
/// </summary>
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
if (error == SslPolicyErrors.None)
{
return true; // already determined to be valid
}
switch (cert.GetCertHashString())
{
// thumbprints/hashes of allowed certificates (uppercase)
case "066CF9CAD814DE2097D368F22D3A7D398B87C4D6":
case "5B82C96685E3A20079B8CE7AFA32554D55DB9611":
Debug.WriteLine("Trusting X509Certificate '" + cert.Subject + "'");
return true;
default:
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 14
<configuration>
<system.net>
<settings>
<servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" />
</settings>
</system.net>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这适合我.谢谢
修改 web.config 对我有用
我使用 Steve Ellinger 的回答和一些谷歌搜索做到了。基本上,我必须:
这是 web.config 片段...
<configuration>
<system.net>
<settings>
<servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" />
</settings>
</system.net>
<system.serviceModel>
<client>
<endpoint ... behaviorConfiguration="DisableServiceCertificateValidation" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="DisableServiceCertificateValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"
revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31397 次 |
| 最近记录: |