gpt4 book ai didi

c# - 连接 WCF 服务时遇到问题

转载 作者:行者123 更新时间:2023-11-30 21:45:18 25 4
gpt4 key购买 nike

我在下面创建自定义绑定(bind)从配置中获取端点地址,然后尝试向 WCF 服务发送请求。

BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

var endpointAddress = "";

ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");

for (int i = 0; i < clientSection.Endpoints.Count; i++)
{
if (clientSection.Endpoints[i].Name == "HTTPS_Port")
endpointAddress = clientSection.Endpoints[i].Address.AbsoluteUri;
}

EndpointAddress address = new EndpointAddress(endpointAddress);
MyWCFService svc = new MyWCFService(binding, address);

出现以下错误

The provided URI scheme 'https' is invalid; expected 'http'.\r\nParameter name: via"}

最佳答案

您没有使用安全模式进行传输。你需要添加

    binding.Security.Mode = BasicHttpSecurityMode.Transport;



According to definition =>



//Security is provided using HTTPS. The service must be configured with SSL
// certificates. The SOAP message is protected as a whole using HTTPS. The service
// is authenticated by the client using the service’s SSL certificate. The client
// authentication is controlled through the System.ServiceModel.HttpTransportSecurity.ClientCredentialType.

不要使用

binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

此安全模式只能用于基于http的客户端。

根据微软 此模式不提供消息完整性和 secret 性。它提供

//     only HTTP-based client authentication. Use this mode with caution. It should
// be used in environments where the transfer security is being provided by
// other means (such as IPSec) and only client authentication is provided by
// the Windows Communication Foundation (WCF) infrastructure.

注意:托管此服务需要 SSL 证书。请在 IIS 中安装此证书。

关于c# - 连接 WCF 服务时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40268124/

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