【问题标题】:Facing issue when connecting with WCF service连接 WCF 服务时面临的问题
【发布时间】:2016-10-26 16:59:14
【问题描述】:

我在custom bindinggetting end point address from config 下面创建,然后尝试向 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);

我收到以下错误

提供的 URI 方案“https”无效;预期的 'http'。\r\n参数名称:通过"}

【问题讨论】:

    标签: c# wcf wcf-security


    【解决方案1】:

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

        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 的客户端。

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

    //     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 中安装。

    【讨论】:

    • 我正在连接到客户端共享的soap服务。如果我将“传输”与“Https”一起使用,是否需要在绑定(配置文件)中提及证书?或者此证书必须由客户端在托管此服务的 IIS 上安装?
    • 证书并不只特定于 wcf。您需要将其安装在托管的 IIS 机器中。@simbada
    猜你喜欢
    • 2016-11-12
    • 1970-01-01
    • 2010-12-11
    • 2022-07-26
    • 1970-01-01
    • 2010-12-18
    • 2010-10-11
    • 1970-01-01
    • 2021-04-25
    相关资源
    最近更新 更多