C# ClientBase和https连接。提供的URI方案“https”无效;应为“http”。参数名称:via

C# ClientBase和https连接。提供的URI方案“https”无效;应为“http”。参数名称:via,c#,wcf,rest,client,C#,Wcf,Rest,Client,我正在尝试使用ClientBase类与REST服务通信。下面是我的代码: class MyService: ClientBase<IMyService>, IMyService { public GridVisionService(Uri baseAddress) : base(new WebHttpBinding(), new EndpointAddress(baseAddress)) { this.Endpoint.Behavior

我正在尝试使用ClientBase类与REST服务通信。下面是我的代码:

class MyService: ClientBase<IMyService>, IMyService
{
    public GridVisionService(Uri baseAddress)
        : base(new WebHttpBinding(), new EndpointAddress(baseAddress))
    {
        this.Endpoint.Behaviors.Add(new WebHttpBehavior());
    }

    #region IMyServiceMembers

    public void DoSomething()
    {
        using (new OperationContextScope(this.InnerChannel)) // Line that throws the exception
        {
            WebOperationContext.Current.OutgoingRequest.Headers.Add("details", "details");
        } // End of OperationContextScope

        this.Channel.DoSomething();
    }

    #endregion
}

但是,它抛出了一个关于期望HTTP而不是HTTPS的异常。搜索时,我发现同一错误的多个实例,但在所有情况下,我都发现app.config正在配置连接。就我而言,我不是。有人知道如何让我的服务预期使用https吗?

创建WebHttpBinding时,请将其安全属性设置为Transport

System.ServiceModel.WebHttpBinding w = new System.ServiceModel.WebHttpBinding();
w.Security = new System.ServiceModel.WebHttpSecurity();
w.Security.Mode = System.ServiceModel.WebHttpSecurityMode.Transport;

创建WebHttpBinding时,请将其安全属性设置为Transport

System.ServiceModel.WebHttpBinding w = new System.ServiceModel.WebHttpBinding();
w.Security = new System.ServiceModel.WebHttpSecurity();
w.Security.Mode = System.ServiceModel.WebHttpSecurityMode.Transport;

我似乎找不到WebHttpsBinding类。WebHttpBinding类位于System.ServiceModel命名空间中,但似乎没有WebHttpsBinding类。我似乎找不到WebHttpsBinding类。WebHttpBinding类位于System.ServiceModel命名空间中,但似乎没有WebHttpsBinding类。