通过HTTPS访问web服务给ArgumentException
问题描述:
在C#中,我试图访问位于HTTPS地址的Web服务。我的代码是在一个类库中定义的,它在主应用程序中使用DLL引用 - 因此在这里不可能使用App.config
文件配置Web服务的标准方式。 我的代码基本上等于以下内容:通过HTTPS访问web服务给ArgumentException
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'。
参数名称:通过
任何人都可以发现问题是什么?
答
由于您使用的是SSL/TLS,即https,因此使用此信息创建WSHttpBinding实例是有意义的。例如。改变
new System.ServiceModel.WSHttpBinding()
到 新System.ServiceModel.WSHttpBinding(SecurityMode.xxx)
其中XXX在http://msdn.microsoft.com/en-us/library/ms575161.aspx定义
[所提供的URI方案的 'https' 的
可能重复的无效;预计'http'。参数名称:via](http://*.com/questions/2435823/the-provided-uri-scheme-https-is-invalid-expected-http-parameter-name-via) – vcsjones