WCF中对同一服务的多服务行为
我们可以在WCF中将多个服务行为附加到同一个服务上吗?如果可以,我们怎么做?通过配置文件或作为属性?可以。 您需要配置您的行为,并在服务标签中配置每个行为,如下所示:WCF中对同一服务的多服务行为,wcf,wcf-data-services,wcf-ria-services,wcf-binding,wcf-security,Wcf,Wcf Data Services,Wcf Ria Services,Wcf Binding,Wcf Security,我们可以在WCF中将多个服务行为附加到同一个服务上吗?如果可以,我们怎么做?通过配置文件或作为属性?可以。 您需要配置您的行为,并在服务标签中配置每个行为,如下所示: <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior"> <!-- First behavior: ht
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- First behavior:
http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- Second behavior, with secure endpoint exposed at {base address}/secure:
http://localhost/servicemodelsamples/service.svc/secure -->
<endpoint address="secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</service>
ICalcular的相同服务,用于两种不同的行为
阅读更多信息:是的,我们可以创建多个端点
<services>
<service name="ReportService.ReportService">
<endpoint
address="ReportService"
binding="netTcpBinding"
contract="ReportService.IReportService">
</endpoint>
<endpoint
address="ReportService"
binding="basicHttpBinding"
contract="ReportService.IReportService">
</endpoint>
</service>
</services>
现在它将与netTcpBinding一起工作是的,您可以
ServiceEndpoint具有行为集。
因此,如果您使用C#代码创建服务,您可以向该集合添加任何行为:标准行为或您的行为。有关如何创建自定义行为并将其添加到的示例。请记住,您可以根据需要创建和添加任意多的行为
如果要在配置中添加行为,则需要创建行为配置扩展。并将其添加到配置文件中的端点
编辑:
服务行为感谢李嘉图的回复,但我在这里需要的是向同一服务添加两个behaviorConfiguration。在您展示的示例中,我们正在添加两个端点行为。是否可以向同一Calclator服务添加更多的行为配置,如验证服务行为。例如。这样行吗?不,对于服务器端点,您需要在服务标记中设置行为,因此,您将需要创建不同的服务和不同的端点,但您可以使用相同的契约。
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_IReportService" />
</netTcpBinding>
<basicHttpBinding>
<binding name="basicHttpBinding_IReportService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="netTcpBinding_IReportService" contract="ServiceReference.IReportService"
name="netTcpBinding_IReportService">
</endpoint>
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_IReportService" contract="ServiceReference.IReportService"
name="basicHttpBinding_IReportService">
</endpoint>
</client>
ServiceReference.ReportServiceClient client = new ServiceReference.ReportServiceClient(netTcpBinding_IReportService);