2012-10-11 73 views
0

我成功将城堡WCF设施与我的服务相结合。现在我尝试配置基于BasicHttpBinding的HTTPS通信。温莎城堡WCF设施HTTPS

根据下面的博客文章,这不应该是一个大问题:http://blog.adnanmasood.com/2008/07/16/https-with-basichttpbinding-note-to-self/

这里是我的设置。在客户端,我使用以下代码配置Windsor容器:

BasicHttpBinding clientBinding = new BasicHttpBinding(); 

    // These two lines are the only thing I changed here to allow HTTPS 
    clientBinding.Security.Mode = BasicHttpSecurityMode.Transport; 
    clientBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
    // Everything else worked well with HTTP 

    clientBinding.MaxReceivedMessageSize = 163840; 
    clientBinding.MaxBufferSize = (int)clientBinding.MaxReceivedMessageSize; 

    container = new WindsorContainer(); 
    container.AddFacility<WcfFacility>(); 
    container.Register(
     Component.For<IClientService>() 
     .AsWcfClient(new DefaultClientModel { 
       Endpoint = WcfEndpoint.BoundTo(clientBinding) 
       .At(configuration.Get(CFGKEY_SERVICE_CLIENT)) 
     }) 
    ); 

除此之外,我在客户端没有任何配置。这使用HTTP通信很好。

服务器端得到Web.config中配置如下:

<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name=""> 
     <serviceMetadata httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
    multipleSiteBindingsEnabled="true" /> 

当我试图通过HTTPS连接://,我得到以下异常:

System.ServiceModel.EndpointNotFoundException:在https://myuri.com/Services/Client.svc处没有可以接受消息的端点。

任何想法缺少什么? 预先感谢您。

回答

2

我自己修复了这个问题,上面的代码是正确的,问题已经在服务器端的Windsor服务安装程序中找到了。以下每个服务点的片段将完成这项工作。如您所见,我已将绝对服务URI以及传输模式(http或https)放入Web.config文件的应用程序设置部分。当然,使用默认的WCF配置模型会很好,但这不起作用。

 .Register(
      Component 
      .For<MyNamespace.ContractInterface>() 
      .ImplementedBy<MyNamespace.ImplementationClass>() 
      .Named("ServiceName").LifestylePerWcfOperation() 
      .AsWcfService(
       new DefaultServiceModel().Hosted().AddEndpoints(
        WcfEndpoint.BoundTo(new BasicHttpBinding { 
         Security = new BasicHttpSecurity { 
          Mode = (WebConfigurationManager.AppSettings["Service.WCFFacility.TransportMode"] == "http") ? BasicHttpSecurityMode.None : BasicHttpSecurityMode.Transport, 
          Transport = new HttpTransportSecurity { 
           ClientCredentialType = HttpClientCredentialType.None 
          } 
         } 
        }).At(WebConfigurationManager.AppSettings["Service.WCFFacility.Endpoint"]) 
       ) 
      ) 
     ); 

除应用程序设置键之外,服务器配置保持如上所示。

希望这可能会帮助遇到类似问题的人。