【问题标题】:Self - hosted WCF server and SSL自托管 WCF 服务器和 SSL
【发布时间】: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,我应该在哪里为客户端和服务器设置证书? 谢谢。

【问题讨论】:

    标签: c# wcf ssl


    【解决方案1】:

    尝试改变

    <security mode="TransportCredentialOnly">
    

    到

    <security mode="Transport">
    

    如果有任何改进,请告诉我们。这应该使您的客户端允许 HTTPS 连接。

    【讨论】:

    • 在此更改后,我收到:向myhost:8002/Admin 发出 HTTP 请求时出错。这可能是由于在 HTTPS 情况下未使用 HTTP.SYS 正确配置服务器证书。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。
    • 我在 xml 文件中没有服务器配置。所有配置都是用 c# 代码编写的 :( ...
    • 你可以为配置服务器发布简单的 xml,我应该检查在 c# 代码中配置的服务器代码吗?
    猜你喜欢
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多