2011-09-13 78 views
1

在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'。
參數名稱:通過

任何人都可以發現問題是什麼?

+0

可能重複的無效;預計'http'。參數名稱:via](http://stackoverflow.com/questions/2435823/the-provided-uri-scheme-https-is-invalid-expected-http-parameter-name-via) – vcsjones

回答

0

由於您使用的是SSL/TLS,即https,因此使用此信息創建WSHttpBinding實例是有意義的。例如。改變

new System.ServiceModel.WSHttpBinding() 

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

其中XXXhttp://msdn.microsoft.com/en-us/library/ms575161.aspx定義

[所提供的URI方案的 'https' 的