[英]Castle Windsor WCF Facility HTTPS
我成功地将Caste WCF Facility与我的服务整合在一起。 现在我尝试配置基于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上没有可以接受该消息的端点监听。
有什么想法缺少什么? 先感谢您。
我自己修正了,上面的代码是正确的,问题已经在我的服务器端的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"])
)
)
);
除应用程序设置键外,服务器配置仍如上所示。
希望这可以帮助遇到类似问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.