C# 提供的 URI 方案“http”无效;预期的“https”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1690784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:00:55  来源:igfitidea点击:

provided URI scheme'http' is invalid; expected 'https'

c#wcf

提问by Tara Singh

I have a RESTful Web Service hosted in IIS 6.0, I am able to Browse the Service in browser. When i am trying to access the same service via Client console App, it is giving me the following error:

我有一个托管在 IIS 6.0 中的 RESTful Web 服务,我能够在浏览器中浏览该服务。当我尝试通过客户端控制台应用程序访问相同的服务时,出现以下错误:

"provided URI scheme'http' is invalid; expected 'https', Parameter name: Via"

My WebService web.config has this settings:

我的 WebService web.config 具有以下设置:

<system.serviceModel>  
<services>  
  <service behaviorConfiguration="ServiceBehavior" name="TestAPI">
    <endpoint address="" behaviorConfiguration="RESTFriendly" binding="webHttpBinding" contract="ITestAPI" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>     
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="RESTFriendly">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

My Client App has App.config from where i am getting the address :

我的客户端应用程序有 App.config 来自我获取地址的地方:

<appSettings>
<add key="WEBSERVICE" value="URL"/>

in the Main method :

在主要方法中:

WebChannelFactory<ITestAPI> cf = new WebChannelFactory<IAPI>(baseAddress);
            WebHttpBinding wb =cf.Endpoint.Binding as WebHttpBinding;
            wb.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            wb.Security.Mode = WebHttpSecurityMode.Transport;
            cf.Credentials.UserName.UserName = "usermane";
            cf.Credentials.UserName.Password = "password";

            ITestAPI channel = cf.CreateChannel();
            string msg = channel.TestMethod(); 

When it tries to call TestMethod, it gives me this error.

当它尝试调用 TestMethod 时,它给了我这个错误。

采纳答案by James Bailey

You're setting the security to transport mode, which is HTTPS, with this line:

您正在使用以下行将安全性设置为传输模式,即 HTTPS:

wb.Security.Mode = WebHttpSecurityMode.Transport;

wb.Security.Mode = WebHttpSecurityMode.Transport;

Is the value of baseAddressan HTTP or HTTPS address?

baseAddressHTTP 还是 HTTPS 地址的值?