[英]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.