1

ClientBaseこのクラスを使用してRESTサービスと通信しようとしています。以下は私のコードです:

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の使用を期待させる方法を誰かが知っていますか?

4

1 に答える 1

4

WebHttpBinding を作成するときは、その Security プロパティを Transport に設定します。

System.ServiceModel.WebHttpBinding w = new System.ServiceModel.WebHttpBinding();
w.Security = new System.ServiceModel.WebHttpSecurity();
w.Security.Mode = System.ServiceModel.WebHttpSecurityMode.Transport;
于 2012-05-08T15:47:29.243 に答える