Accessing webservice through HTTPS gives ArgumentException
In C#, I am trying to access a web service located on an HTTPS address. My code is defined in a class library, which is referred to in the main application(s) using DLLs — so the standard way of configuring the web services with an App.config
file is not possible here.
My code is essentially equal to the following:
var remoteAddress = new System.ServiceModel.EndpointAddress(
"https://myUrl.com/Service.svc");
MyServiceClient myClient = new MyServiceClient(
new System.ServiceModel.WSHttpB开发者_开发问答inding(),
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");
But even though I use WSHttpBinding I get an ArgumentException with the message:
The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via
Can anyone spot what the problem is?
Since you are using SSL/TLS, i.e. https, it would make sense to create the WSHttpBinding instance with this information. E.g. change
new System.ServiceModel.WSHttpBinding()
to new System.ServiceModel.WSHttpBinding(SecurityMode.xxx)
where xxx is defined in http://msdn.microsoft.com/en-us/library/ms575161.aspx
精彩评论