2011-09-25 135 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有关于保护元数据的文章。它还保证服务本身(这是合理的 - 为什么安全元数据而不是服务?)

相关问题