2013-07-04 33 views
2

在我的ASP.NET WebForms項目中,我引用了WCF服務庫項目,該項目包含用於每個業務對象的不同WCF服務。這些服務託管在IIS中,並且可以通過我在Global.asax中定義的路由獲取WSDL:通過一個路由爲每個服務創建一個WSDL。WCF:如何將多個服務合併到一個WSDL中

我真正需要的是一些選擇服務的能力,我希望爲不同的客戶提供服務,併爲選定的服務集生成一個單一的WSDL。

+0

單個WCF服務將擁有一個WSDL。例如,您不能在同一個WSDL上使用服務A,服務B和服務C,至少不是我所知。 – Tim

回答

7

是的,它可以配置WCF路由服務並獲得WSDL文件形成單個服務。

第1步 -HttpGetEnabled set to 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> 

您完成所有的工作。 您可以直接通過以下URLS單獨訪問您的服務的WSDL文件:

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

很棒的例子,有人需要將其標記爲答案。 – htm11h

0

解決方案中的問題是:你給你的客戶你的web服務PremiumWCFService和StandardService的地址的WSDL和客戶端(WCF)可以直接使用它,無需檢查,並且可以在沒有呼叫路由服務的情況下調用您的Web服務。

相關問題