gpt4 book ai didi

wcf - 为每个端点指定 CaSTLe WCF 集成工具端点行为

转载 作者:行者123 更新时间:2023-12-04 05:37:25 25 4
gpt4 key购买 nike

我正在使用 CaSTLe WCF 集成工具,并且我的第一个 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>());

最佳答案

好的。我终于想通了这一点。事实证明,我的大部分问题都与 Azure 仿真环境有关,而不是与 CaSTLe WCF 集成有关。答案非常简单——只需设置 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())));

关于wcf - 为每个端点指定 CaSTLe WCF 集成工具端点行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11749693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com