我正在尝试使用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/"));
但是,它会抛出关于期望 HTTP 而不是 HTTPS 的异常。在搜索时,我发现了相同错误的多个实例,但是在所有情况下,我发现 app.config 正在配置连接。就我而言,我不是。有谁知道我怎样才能让我的服务期望使用 https?