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

しかし、それは、HTTPSではなくHTTPを期待について例外がスローされます。検索では、同じエラーの複数のインスタンスが見つかりましたが、すべてのケースでapp.configが接続を構成していることがわかりました。私の場合、私はそうではありません。誰も私のサービスがhttpsを使用することを期待できるようにする方法を知っていますか?

答えて

3

[this post] [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

私の悪い、私は答えを更新 –

関連する問題