【问题标题】:Accessing webservice through HTTPS gives ArgumentException通过 HTTPS 访问 Web 服务会产生 ArgumentException
【发布时间】:2011-11-16 05:12:30
【问题描述】:

在 C# 中,我试图访问位于 HTTPS 地址上的 Web 服务。我的代码是在一个类库中定义的,在主应用程序中使用 DLL 引用该类库 — 因此,使用 App.config 文件配置 Web 服务的标准方法在这里是不可能的。 我的代码基本上等于以下内容:

var remoteAddress = new System.ServiceModel.EndpointAddress(
    "https://myUrl.com/Service.svc");
MyServiceClient myClient = new MyServiceClient(
    new System.ServiceModel.WSHttpBinding(),
    remoteAddress);
myClient.ClientCredentials.ClientCertificate.SetCertificate(
    StoreLocation.CurrentUser,
    StoreName.My,
    X509FindType.FindByThumbprint,
    "91 47 0b e8 80 bf ee 68 32 93 f0 d4 ee e6 14 8c e5 0c fa 3e"
    );
myClient.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10);
var myResult = myClient.MyMethod("foo bar");

但即使我使用 WSHttpBinding,我也会收到带有消息的 ArgumentException:

提供的 URI 方案“https”无效;预期为“http”。
参数名称:via

谁能找出问题所在?

【问题讨论】:

标签: c# .net wcf web-services https


【解决方案1】:

由于您使用的是 SSL/TLS,即 https,因此使用此信息创建 WSHttpBinding 实例是有意义的。例如。改变

new System.ServiceModel.WSHttpBinding()

到 新 System.ServiceModel.WSHttpBinding(SecurityMode.xxx)

其中xxx定义在http://msdn.microsoft.com/en-us/library/ms575161.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    相关资源
    最近更新 更多