简体   繁体   English

Castle Windsor WCF设施HTTPS

[英]Castle Windsor WCF Facility HTTPS

I successfully integrated the Caste WCF Facility with my services. 我成功地将Caste WCF Facility与我的服务整合在一起。 Now I try to configure an HTTPS communication based on BasicHttpBinding. 现在我尝试配置基于BasicHttpBinding的HTTPS通信。

According the following blog post, this should not be a big deal: http://blog.adnanmasood.com/2008/07/16/https-with-basichttpbinding-note-to-self/ 根据以下博客文章,这应该不是什么大不了的事: http//blog.adnanmasood.com/2008/07/16/https-with-basichttpbinding-note-to-self/

Here's my setup. 这是我的设置。 On client-side, I configure the Windsor container using the following code: 在客户端,我使用以下代码配置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))
        })
     );

Besides that, I don't have any configuration on client-side. 除此之外,我在客户端没有任何配置。 This worked well using HTTP communication. 这在使用HTTP通信时效果很好。

The server side got the following configuration within Web.config: 服务器端在Web.config中获得以下配置:

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

When I'm trying to connect through https://, I get the following exception: 当我尝试通过https://连接时,我收到以下异常:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at https://myuri.com/Services/Client.svc that could accept the message. System.ServiceModel.EndpointNotFoundException:在https://myuri.com/Services/Client.svc上没有可以接受该消息的端点监听。

Any ideas what's missing? 有什么想法缺少什么? Thank you in advance. 先感谢您。

Fixed it by myself, the above code is correct, the problem has been located inside my Windsor service installer on server-side. 我自己修正了,上面的代码是正确的,问题已经在我的服务器端的Windsor服务安装程序中找到了。 The following snippet for each service point will do the job. 每个服务点的以下代码段都可以完成这项工作。

As you can see, I've put the absolute service URI as well as transport mode (either http or https) into the app settings section of the Web.config file. 如您所见,我已将绝对服务URI以及传输模式(http或https)放入Web.config文件的应用程序设置部分。 Of course it would be nice to use the default WCF configuration model but this did not work. 当然,使用默认的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"])
                )
            )
        );

The server configuration remains as shown above, except the app setting keys. 除应用程序设置键外,服务器配置仍如上所示。

Hope this might help someone experiencing similar problems. 希望这可以帮助遇到类似问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM