gpt4 book ai didi

c# - 自托管 WCF 服务器和 SSL

转载 作者:太空狗 更新时间:2023-10-29 21:30:57 26 4
gpt4 key购买 nike

有自托管的 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 以及我应该在哪里为客户端和服务器设置证书?谢谢。

最佳答案

尝试改变

<security mode="TransportCredentialOnly">

<security mode="Transport">

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

关于c# - 自托管 WCF 服务器和 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3052436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com