【发布时间】:2010-06-16 10:28:07
【问题描述】:
有自托管的 WCF 服务器(不是 IIS),并且是使用命令行生成证书(在 Win Xp 上)
makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=SecureClient -sky exchange -pe
makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=SecureServer -sky exchange -pe
这些证书被添加到服务器代码中,如下所示:
serviceCred.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine,
StoreName.My, X509FindType.FindBySubjectName, "SecureServer");
serviceCred.ClientCertificate.SetCertificate(StoreLocation.LocalMachine,
StoreName.My, X509FindType.FindBySubjectName, "SecureClient");
在完成之前的所有操作后,我创建了简单的客户端来检查与服务器的 SSL 连接。
客户端配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAdminContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://myhost:8002/Admin" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IAdminContract" contract="Admin.IAdminContract"
name="BasicHttpBinding_IAdminContract" />
</client>
</system.serviceModel>
</configuration>
代码:
Admin.AdminContractClient client = new AdminContractClient("BasicHttpBinding_IAdminContract");
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "pass";
var result = client.ExecuteMethod()
在执行期间我收到下一个错误:
The provided URI scheme 'https' is invalid; expected 'http'.\r\nParameter name: via
问题:如何为自托管服务器启用 ssl,我应该在哪里为客户端和服务器设置证书? 谢谢。
【问题讨论】: