0

我成功地将 Caste WCF 设施与我的服务集成在一起。现在我尝试配置基于 BasicHttpBinding 的 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上没有可以接受消息的端点侦听。

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

4

1 回答 1

2

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.

于 2012-10-12T09:50:21.463 回答