Reputation: 10888
I have multiple Service contracts defined in one WCF library which are hosted under a Windows Service. These Services are exposed as follows in Windows Service config file:
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
Now, when I add service reference in my client application,
Is it possible to add just one service reference for above two services or
I need to separate reference for each service/service contract.
Here are my application details:
I have three different projects:
Now, The App.Config in WCF Service Library is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000" messageEncoding="Mtom">
<readerQuotas maxDepth="500" maxStringContentLength="500000000" maxArrayLength="500000000"
maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
name="ReportingComponentLibrary.TemplateReportService">
<endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And App.Config in Windows Service is same as above.
Now in my client application, I need to consume methods from both TemplateService and TemplateReportService.
So, I can always two different Service References as:
http://localhost:8080/ReportingComponentLibrary/TemplateService/ and
http://localhost:8080/ReportingComponentLibrary/TemplateReportService/
This is all working fine.
But I was wondering if there is any way(apart from the wrapper workaround you have suggested) by which I need to add only one reference and I can call methods from both the services.
Upvotes: 1
Views: 3377
Reputation: 65391
One Service Reference = One Service Contract
Your Windows service has many services inside it, each with it's own contract.
There is however nothing stopping you creating a single contract that contains the functionality of all the services, then creating a class that implements that contract, but is simply a pass through layer to the other servcies.
Upvotes: 2
Reputation: 22733
As it stands, I don't think this is possible, you will need 2 service references as they both implement seperate contracts. Assuming you have control of the service code, you could implement a workaround where you create a service wrapper to implements both the contracts by pointing to the two seperate services. That would allow you to have one service reference. Is there a particular issue as to why you want them both in one service as opposed to two?
EDIT: This Blog Article - Meineck.Net shows you how you can configure your services to achieve what you're after, but again it's pretty much a work around. Good luck.
Upvotes: 5