tags:

views:

453

answers:

2

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.

Update:

Here are my application details:

I have three different projects:

  1. WCF Service Library
  2. Windows Service for hosting above WCF Service
  3. Client - Console Application for Testing

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.

+3  A: 

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.

Tanner
Thanks for your reply. Well, no particular reason except -- because both the services will be used in one application, so wanted to have the client application add just one reference rather than two/multiple.
inutan
+1 exactly - one service reference = reference to **one** service - can't be reference to multiple services at once
marc_s
even if both belongs to one WCF library?
inutan
Having a quick search around the web I found a couple of links that might be useful to you:http://www.aspfree.com/c/a/ASP.NET/Developing-a-WCF-Service-Library-and-Hosting-it-as-WCF-Web-Service-Using-VS2K8/http://msdn.microsoft.com/en-us/library/bb924405.aspxhttp://msdn.microsoft.com/en-us/library/bb332338.aspxIf possible, can you provide further details of your scenario and configuration.
Tanner
+1  A: 

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.

Shiraz Bhaiji