2009-11-06 79 views
18

我有一個REST風格的Web服務託管在IIS 6.0中,我可以在瀏覽器中瀏覽服務。當我試圖通過客戶端控制檯應用程序來訪問相同的服務,這是給我下面的錯誤:提供URI scheme'http'無效;預計'https'

"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"/> 

在Main方法:

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的,它給了我這個錯誤。

help plz。提前致謝。

回答

43

你設置安全傳輸模式,這是HTTPS,這條線:

wb.Security.Mode = WebHttpSecurityMode.Transport;

baseAddress的HTTP值或HTTPS地址?

+1

該值是Http地址。 –

+4

這就是問題所在。你指定你想要一個安全的傳輸,但HTTP不是一個安全的傳輸。 –

+0

謝謝你的回答。 –

相關問題