提供的URI方案'http'无效;预期'https'

时间:2009-11-06 22:02:24

标签: c# wcf

我在IIS 6.0中托管了RESTful Web服务,我可以在浏览器中浏览服务。当我尝试通过客户端控制台应用程序访问相同的服务时,它给我以下错误:

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

我的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>

我的客户端应用程序有App.config,我从中获取地址:

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

主方法中的

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(); 

当它试图调用TestMethod时,它会给我这个错误。

1 个答案:

答案 0 :(得分:51)

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

wb.Security.Mode = WebHttpSecurityMode.Transport;

baseAddress的值是HTTP还是HTTPS地址?

相关问题