gpt4 book ai didi

asp.net - WCF:如何将多个服务组合到单个 WSDL 中

转载 作者:行者123 更新时间:2023-12-02 10:25:02 24 4
gpt4 key购买 nike

在我的 ASP.NET WebForms 项目中,我引用了 WCF 服务库项目,该项目包含针对每个业务对象的不同 WCF 服务。这些服务托管在 IIS 中,并且可以通过我在 Global.asax 中定义的路由获取 WSDL:每个服务通过一个路由获得一个 WSDL。

我真正需要的是 - 能够选择我想要为不同客户提供的服务并为所选服务集生成单个 WSDL。

最佳答案

是的,可以配置 WCF 路由服务并从其背后的单个服务获取 WSDL 文件。

第 1 步 -HttpGetEnabled 设置为 true 并在路由器服务后面的所有 WCF 服务中配置 MEX 端点

 <service behaviorConfiguration="routingBehv" name="System.ServiceModel.Routing.RoutingService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfRoutingService/RoutingService.svc"/>
</baseAddresses>
</host>
<endpoint address="http://localhost/WcfRoutingService/RoutingService.svc" binding="mexHttpBinding" name="mexEndpoint" contract="System.ServiceModel.Routing.IRequestReplyRouter"/>
</service>

步骤 2- 配置路由服务

添加端点

<endpoint address="" binding="mexHttpBinding" name="mexEndpoint" contract="System.ServiceModel.Routing.IRequestReplyRouter"/>

添加服务行为

 <behaviors>
<serviceBehaviors>
<behavior>
<routing routeOnHeadersOnly="false" filterTableName="routingTable" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="false" />
</behavior>

</serviceBehaviors>
</behaviors>

客户端端点地址应指定“MEX”端点地址

 <client>
<endpoint address="http://localhost/PremiumWcfService/PremiumWCFService.svc/mex" binding="mexHttpBinding" contract="*" name="PremiumServiceMex"/>
<endpoint address="http://localhost/StandardWCFService/StandardWCFService.svc/mex" binding="mexHttpBinding" contract="*" name="StandardServiceMex"/>
</client>

指定路由表

<routing>
<filters>
<filter name="StandardServiceMexFilter" filterType="EndpointAddress" filterData="http://tempuri.org/WcfRoutingService/RoutingService.svc/StandardService" />
<filter name="PremiumServiceMexFilter" filterType="EndpointAddress" filterData="http://tempuri.org/WcfRoutingService/RoutingService.svc/sPreminuService" />
</filters>
<filterTables>
<filterTable name="routingTable">
<add filterName="StandardServiceMexFilter" endpointName="StandardServiceMex"/>
<add filterName="PremiumServiceMexFilter" endpointName="PremiumServiceMex"/>
</filterTable>
</filterTables>
</routing>

你已经完成了。您可以通过以下 URL 直接访问您的服务的 WSDL 文件:

http://localhost/WcfRoutingService/RoutingService.svc/StandardService
http://localhost/WcfRoutingService/RoutingService.svc/PremiumService

关于asp.net - WCF:如何将多个服务组合到单个 WSDL 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17476156/

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