简体   繁体   中英

Castle Windsor WCF Facility HTTPS

I successfully integrated the Caste WCF Facility with my services. Now I try to configure an HTTPS communication based on BasicHttpBinding.

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/

Here's my setup. On client-side, I configure the Windsor container using the following code:

    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.

The server side got the following configuration within 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:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at https://myuri.com/Services/Client.svc that could accept the message.

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. 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. Of course it would be nice to use the default WCF configuration model but this did not work.

        .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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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