2011-09-25 120 views
1

我的解決方案中有2個控制檯應用程序。這是我的WCF服務:WCF中的傳輸安全性

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace TransportSecTaulty 
{ 
    [ServiceContract] 
    public interface ITestService 
    { 
     [OperationContract] 
     void CallMe(string message); 
    } 
} 


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace TransportSecTaulty 
{ 
    public class TestService : ITestService 
    { 
     public void CallMe(string message) 
     { 
      Console.BackgroundColor = ConsoleColor.Green; 
      Console.Write(message); 
      Console.BackgroundColor = ConsoleColor.Black; 
     } 
    } 
} 

這是我這是我的託管WCF服務的應用程序的app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name=""> 
        <serviceMetadata httpsGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     <services> 
      <service name="TransportSecTaulty.TestService"> 
       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="serviceConfig" contract="TransportSecTaulty.ITestService"> 
        <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
       <host> 
        <baseAddresses> 
         <add baseAddress="https://localhost:8734/Design_Time_Addresses/TransportSecTaulty/TestService/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services> 
     <bindings> 
     <basicHttpBinding> 
      <binding name="serviceConfig"> 
      <security mode="Transport"> 
      </security> 
      </binding> 
     </basicHttpBinding> 
     </bindings> 
    </system.serviceModel> 
</configuration> 

我的服務可以正常啓動,沒有任何問題。然而,當我嘗試在我的客戶端添加服務引用我得到這個錯誤:

There was an error downloading 'https://localhost:8734/Design_Time_Addresses/TransportSecTaulty/TestService/'. 
The underlying connection was closed: An unexpected error occurred on a send. 
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. 
An existing connection was forcibly closed by the remote host 
Metadata contains a reference that cannot be resolved: 'https://localhost:8734/Design_Time_Addresses/TransportSecTaulty/TestService/'. 
An error occurred while making the HTTP request to https://localhost:8734/Design_Time_Addresses/TransportSecTaulty/TestService/. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. 
The underlying connection was closed: An unexpected error occurred on a send. 
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. 
An existing connection was forcibly closed by the remote host 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

我無法瀏覽我的役的瀏覽器。然而,同樣的事情在http上完美工作。問題只出現在https中。

任何想法可能是錯誤的?

回答

1

你有

<endpoint address="" 
      binding="basicHttpBinding" 
      bindingConfiguration="serviceConfig" 
      contract="TransportSecTaulty.ITestService"> 

,但我希望你要binding="basicHttpsBinding"

-1

你應該使用的WSHttpBinding ......

1

您正在試圖保護以https元數據,而該服務本身是純粹的http。那真的是你想要的嗎?

MSDN有關於保護元數據的文章。它還保證服務本身(這是合理的 - 爲什麼安全元數據而不是服務?)