2012-05-08 31 views
0

我正嘗試使用ClientBase類與REST服務進行通信。下面是我的代碼:ClientBase和https連接。提供的URI方案'https'無效;預計'http'。參數名稱:via

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 
} 

我跑我的課像下面這樣:

MyService myService = new MyService(new Uri("https://localhost:8080/MyService/")); 

然而,它拋出約期待HTTP,而不是HTTPS除外。在搜索時,我發現了同一個錯誤的多個實例,但是在所有情況下,我發現app.config正在配置連接。在我的情況下,我不是。有誰知道我可以如何讓我的服務期望使用https?

回答

3

請參閱[本文] [1]。

當您創建WebHttpBinding時,將其安全屬性設置爲傳輸。

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

我似乎無法找到WebHttpsBinding類。 WebHttpBinding類位於System.ServiceModel名稱空間中,但似乎沒有WebHttpsBinding類。 – Kyle

+0

我不好,我更新了答案 –

相關問題