我正在使用Castle WCF Integration Facility,我已经为我的第一个webHttp端点正常工作了。要使此端点起作用,需要端点启用WebHttpBehavior。我能够通过以下方式实现这一目标:
container.Register(Component.For<IEndpointBehavior>()
.ImplementedBy<WebHttpBehavior>());
当我尝试使用与WebHttpBehavior不兼容的BasicHttpBinding启用第二个端点时,这会成为一个问题。
是否有人指定上面的IEndPointBehavior注册仅适用于某个端点?
这是该服务的完整安装程序:
container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<IDiagnosticService>()
.ImplementedBy<DiagnosticService>()
.Named("DiagnosticService")
.LifestyleTransient()
.AsWcfService(new DefaultServiceModel()
.Hosted()
.AddEndpoints(WcfEndpoint.BoundTo(new WebHttpBinding()).At("json"))
.AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding()).At("soap"))
.PublishMetadata(o => o.EnableHttpGet())));
container.Register(Component.For<IEndpointBehavior>()
.ImplementedBy<WebHttpBehavior>());
答案 0 :(得分:3)
确定。我终于想通了。事实证明,我的大多数问题都与Azure仿真环境有关,而不是Castle WCF Integration。答案很简单 - 只需设置ServiceEndpoint实例并使用WcfEndpoint.FromEndpoint()方法。
这是我的工作安装程序:
String internalEndpointAddress = string.Format("http://{0}/DiagnosticService.svc",
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint);
// This ContractDescription instance must be used for both endpoints in this case
ContractDescription description = ContractDescription.GetContract(typeof(IDiagnosticService));
// Create JSON webHTTP Binding
WebHttpBinding webhttpbinding = new WebHttpBinding();
string jsonURI = internalEndpointAddress + "/json";
EndpointAddress jsonEndpointAddress = new EndpointAddress(new Uri(jsonURI));
ServiceEndpoint jsonEndpoint = new ServiceEndpoint(description, webhttpbinding, jsonEndpointAddress);
jsonEndpoint.Behaviors.Add(new WebHttpBehavior());
// Create WSHTTP Binding
WSHttpBinding wsHttpBinding = new WSHttpBinding();
string soapURI = internalEndpointAddress + "/soap";
EndpointAddress soapEndpointAddress = new EndpointAddress(new Uri(soapURI));
ServiceEndpoint soapEndpoint = new ServiceEndpoint(description, wsHttpBinding, soapEndpointAddress);
container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<IDiagnosticService>()
.ImplementedBy<DiagnosticService>()
.Named("DiagnosticService")
.LifestyleTransient()
.AsWcfService(new DefaultServiceModel()
.Hosted()
.AddEndpoints(WcfEndpoint.FromEndpoint(jsonEndpoint))
.AddEndpoints(WcfEndpoint.FromEndpoint(soapEndpoint))
.PublishMetadata(o => o.EnableHttpGet())));