我有一個包含幾個WCF服務的程序集,每個服務都有自己的合同。這一切都很好。在App.config該服務的服務配置是這樣的:幾個WCF服務可以共享一個公共BaseAddress嗎?
<services>
<service behaviorConfiguration="WcfService.AlyzaServiceBehavior"
name="Sam.Alyza.WcfService.ServiceWebsites">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceWebsites">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Websites/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Sam.Alyza.WcfService.LogReaderServiceBehavior"
name="Sam.Alyza.WcfService.ServiceLogReader">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceLogReader">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/LogReader/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Sam.Alyza.WcfService.ServiceSystemverwaltungBehavior"
name="Sam.Alyza.WcfService.ServiceSystemverwaltung">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceSystemverwaltung">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Systemverwaltung/" />
</baseAddresses>
</host>
</service>
[...]
</services>
因爲我有一記大項目,更多的合同,我希望有一種方法來共享之間的BaseAddress不同的服務合同。
如果這只是一個具有不同契約和端點的服務,我可以設置一個ommon baseaddress,但是如何爲多個服務設置一個通用baseaddress?
當然,我需要爲客戶端類似的東西。
另一點是baseAddress不過是當前的位置,可以這麼說。這個想法是所有的端點通常都是相對於baseAddress的。因此,如果您試圖跨所有服務共享相同的baseAddress,則會限制您的部署選項。 – 2009-01-12 20:40:16
如果您正在尋找一種簡化配置的方法,您將不得不切換到使用代碼而不是配置接線。您可以編程方式創建ServiceHost和ServiceEndpoint實例,並可能從數據庫中提取Uri.AbsolutPath值。 – 2009-01-12 20:43:02