2010-03-12 30 views
226

我想通過basicHttpBinding通過https使用WCF服務。這裏是我的web.config:提供的URI方案'https'無效;預計'http'。參數名稱:通過

<service behaviorConfiguration="MyServices.PingResultServiceBehavior" 
    name="MyServices.PingResultService"> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" 
    contract="MyServices.IPingResultService"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 

...

<bindings> 
    <basicHttpBinding> 
    <binding name="defaultBasicHttpBinding"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

...

我使用WCFStorm這是能夠檢索所有連接

元數據正確,但是當我調用我得到的實際方法時:

提供的URI方案'https'無效;預計'http'。 參數名稱:via

回答

29

您是在Cassini(vs dev服務器)上還是在安裝了cert的IIS上運行此操作?過去我試圖在開發Web服務器上連接安全端點。

這裏是過去爲我工作的綁定配置。它使用wsHttpBinding而不是basicHttpBinding。我不知道這對你是否有問題。

<!-- Binding settings for HTTPS endpoint --> 
<binding name="WsSecured"> 
    <security mode="Transport"> 
     <transport clientCredentialType="None" /> 
     <message clientCredentialType="None" 
      negotiateServiceCredential="false" 
      establishSecurityContext="false" /> 
    </security> 
</binding> 

和端點

<endpoint address="..." binding="wsHttpBinding" 
    bindingConfiguration="WsSecured" contract="IYourContract" /> 

此外,請確保您更改客戶端配置,使運輸安全。

+1

本地IIS 7使用自簽名的證書安裝 – isg 2010-03-12 21:31:45

+13

「此外,請確保您更改客戶端配置,以實現交通運輸的安全性。」 - 好建議。太容易被忽視了,WCF將不會在錯誤中提供線索。 – 2010-06-03 19:33:19

194

嘗試在你的app.config添加信息憑證,如:

<bindings> 
<basicHttpBinding> 
<binding name="defaultBasicHttpBinding"> 
    <security mode="Transport"> 
    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
    <message clientCredentialType="Certificate" algorithmSuite="Default" /> 
    </security> 
</binding> 
</basicHttpBinding> 
</bindings> 
+25

感謝您對OP的迴應;我遇到了同樣的問題,並將標記的模式從默認的「無」更改爲「傳輸」。 – Otis 2011-04-07 23:29:43

+1

除了因爲某種原因被IIS6拒絕的塊以外,這種方式運行良好。 – 2013-04-09 03:08:35

+3

將相同的配置複製到我的項目中,但沒有任何效果。我錯過了什麼補充嗎? – 2016-02-22 07:32:39

1

的wsHttpBinding是一個問題,因爲Silverlight不支持它!

+0

僅供參考:Windows Phone 7,Windows Phone 8或WinRT也不例外。 – 2013-08-12 22:23:45

+0

我爲silverlight添加了一個答案 – 2017-04-20 00:50:39

19

我和OP完全一樣的問題。我的配置和情況完全相同。在Visual Studio中的測試項目中創建服務引用並確認服務正在運行後,我最終將其縮小爲WCFStorm中的問題。在Storm中,您需要點擊「配置」設置選項(而不是「客戶端配置」)。點擊後,點擊彈出對話框中的「安全」選項卡。確保「身份驗證類型」設置爲「無」(默認爲「Windows身份驗證」)。 Presto,它的工作原理!我總是在WCFStorm中測試我的方法,因爲我正在構建它們,但從未嘗試過使用它來連接到已經在SSL上設置的方法。希望這可以幫助別人!

+0

我有這個完全相同的問題,但我使用「用戶名/密碼身份驗證」的密碼錯誤。事實證明,如果您更改了密碼,則需要單擊該服務的URL和工具欄上的「刷新」按鈕才能獲取該密碼。 – 2016-09-14 14:49:09

13

我在custom binding方案中遇到了同樣的例外情況。任何人使用這種方法,也可以檢查這一點。

我實際上是從local WSDL文件中添加服務參考。它成功添加並且需要將自定義綁定添加到配置文件。但是,實際的服務是https;不是http。所以我將httpTransport元素更改爲httpsTransport。這解決了問題

<system.serviceModel> 
<bindings> 

    <customBinding> 
    <binding name="MyBindingConfig"> 

     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
     messageVersion="Soap11" writeEncoding="utf-8"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     </textMessageEncoding> 

     <!--Manually changed httpTransport to httpsTransport--> 
     <httpsTransport manualAddressing="false" maxBufferPoolSize="524288" 
     maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" 
     bypassProxyOnLocal="false" 
     decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" 
     keepAliveEnabled="true" maxBufferSize="65536" 
     proxyAuthenticationScheme="Anonymous" 
     realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" 
     useDefaultWebProxy="true" /> 
    </binding> 
    </customBinding> 

</bindings> 

<client> 
    <endpoint address="https://mainservices-certint.mycompany.com/Services/HRTest" 
    binding="customBinding" bindingConfiguration="MyBindingConfig" 
    contract="HRTest.TestWebserviceManagerImpl" name="TestWebserviceManagerImpl" /> 
</client> 


</system.serviceModel> 

參考

  1. WCF with custombinding on both http and https
+1

謝謝先生!這正是我正在尋找:) – 2017-08-24 14:59:09

2

要重新蓋在OP的問題:

我連接[到WCF服務]使用能夠正確檢索所有元數據的WCFStorm,但是當我調用我得到的實際方法時:

提供的URI方案'https'無效;預計'http'。參數名稱:via

WCFStorm教程在Working with IIS and SSL中解決了此問題。

他們的解決方案爲我工作:

  1. 要修正這個錯誤,生成WCF服務的配置相匹配的客戶端配置。最簡單的方法是使用Visual Studio。

    • 打開Visual Studio並添加服務引用到服務。 VS將生成一個與服務匹配的app.config文件

    • 編輯app.config文件,以便它可以被WCFStorm讀取。請參閱Loading Client App.config files。確保endpoint/@ name和endpoint/@ contract屬性與wcfstorm中的值匹配。

  2. 將已修改的app.config加載到WCFStorm [使用客戶端配置toobar按鈕]。

  3. 調用該方法。這一次的方法調用將不再失敗

項目(1)實際上最後一顆子彈意味着刪除命名空間前綴是VS預規劃到端點合同屬性,默認情況下「ServiceReference1」

<endpoint ... contract="ServiceReference1.ListsService" ... /> 

所以你加載到WCFStorm在app.config你想要ListsService:

<endpoint ... contract="ListsService" ... /> 
8

遇到同樣的問題,這是我的解決方案在年底如何變成了:

 <basicHttpsBinding> 
      <binding name="VerificationServicesPasswordBinding"> 
       <security mode="Transport"> 
       </security> 
      </binding> 
      <binding name="VerificationServicesPasswordBinding1" /> 
     </basicHttpsBinding> 

我基本上取代使用HTTPS的HTTP每次發生。如果您願意,您可以嘗試添加它們。

+3

應該指出,basicHttpsBinding是4.5和更新。 – Jagd 2015-10-29 17:43:42

40

添加此作爲答案,因爲你不能在評論中做很多花哨的格式。
我有同樣的問題,除了我完全在代碼中創建和綁定我的Web服務客戶端。
原因是DLL被上傳到系統中,該系統禁止使用配置文件。

這是因爲它需要更新通過SSL通信的代碼...

Public Function GetWebserviceClient() As WebWorker.workerSoapClient 
    Dim binding = New BasicHttpBinding() 
    binding.Name = "WebWorkerSoap" 
    binding.CloseTimeout = TimeSpan.FromMinutes(1) 
    binding.OpenTimeout = TimeSpan.FromMinutes(1) 
    binding.ReceiveTimeout = TimeSpan.FromMinutes(10) 
    binding.SendTimeout = TimeSpan.FromMinutes(1) 

    '// HERE'S THE IMPORTANT BIT FOR SSL 
    binding.Security.Mode = BasicHttpSecurityMode.Transport 

    Dim endpoint = New EndpointAddress("https://myurl/worker.asmx") 

    Return New WebWorker.workerSoapClient(binding, endpoint) 
End Function 
+0

您是如何爲您的Web服務創建類的? – kaiyaq 2017-02-10 01:21:27

3

它的一個好要記住,配置文件可以在輔助文件進行分割,使配置的變化在不同的服務器更容易(開發/演示/製作等),而無需重新編譯代碼/應用程序等。 例如,我們使用它們允許現場工程師在不實際觸及「真實」文件的情況下更改端點。

第一步是到綁定部分出了WPF App.Config中的移動到它自己的獨立的文件。

的行爲部分被設置爲允許HTTP和HTTPS(似乎並不具備,如果兩者都允許對應用程序的影響)

<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" /> 

而且我們移動綁定部分出它自己的文件;

<bindings configSource="Bindings.config" /> 

在我們基於協議

<!-- None = http:// --> 
    <!-- Transport = https:// --> 
    <security mode="None" > 

交換機的安全性現在現場工程師bindings.config文件只需要改變Bindings.Config文件和Client.Config我們存儲的每個端點的實際URL。

這樣我們就可以從HTTP端點更改爲https,然後再返回來測試應用程序,而無需更改任何代碼。

希望這會有所幫助。

19

變化 從

<security mode="None"> 

<security mode="Transport"> 

在你的web.config文件。這一變化將允許您使用https而非http

3

如果您在web.config中它做到這一點編程,而不是:

new WebHttpBinding(WebHttpSecurityMode.Transport) 
+0

太好了。我總是討厭.exe.config文件,而不是通過代碼來做所有事情。這解決了我的問題。 – nivs1978 2017-12-21 08:55:15

1

我需要以下綁定找我的工作:

 <binding name="SI_PurchaseRequisition_ISBindingSSL"> 
      <security mode="Transport"> 
      <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" /> 
      </security> 
     </binding> 
相關問題