0

Here is my understanding of how a wcf library project is hosted. Once you create a wcf library project you have your app.config as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfLib.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfLib/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="wsHttpBinding" contract="WcfLib.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

You can simply create an empty console application project (just put a Console.ReadLine() in it), and add a reference to the previous project's assembly, and add the entire services tag as seen above. Now its hosted. It lives as long as that console application lives.

Note the pattern how the markup was written to make this work. Everything in the <services/> stands for a wcf service entity which is to be hosted. In this case hosting was done via conifugration via my console application.

I am looking at if I can follow a similar analogy for wcf service consumption. Can I write my wcf client using the same pattern of configuration? Ultimately I am looking at putting those configurations in a separate config file.

Here are links of previous posts if you are interested in what made me ask this question

deostroll
  • 11,661
  • 21
  • 90
  • 161

2 Answers2

1

Your service doesn't host itself. When you debug your WCF library WCF Service Host is run by your debugger to host your service. You have to do this manually in real environment.

Read about WCF Service Host here.

Edit:

And answering Your question: Yes, you can configure your client in the same manner. See this article

Grzegorz W
  • 3,487
  • 1
  • 21
  • 21
  • +1 for correcting me. But any idea on if wcf client confiugration will work the same *pattern*? – deostroll May 28 '12 at 09:13
  • That is the same markup you get via VS when you add a service reference. If you had 2 or more services to connect to then the serviceModels section would look huge...I am looking at modularizing it; managing the ABC's separately? Basically moving them into separate files... – deostroll May 28 '12 at 10:26
  • So what is Your question exacly? – Grzegorz W May 28 '12 at 10:46
  • One service I am connecting to may have its own binding, contract, endpoint. I just want to move these to a separate *.config file. Similar to the way mentioned here -> http://stackoverflow.com/a/10672636/145682 – deostroll May 28 '12 at 11:00
  • I still see no question. Have you even tried splitting it that way? – Grzegorz W May 28 '12 at 11:06
0

I came across the following SO post. Perhaps my answer lies in that or not...I am not sure

How to tell WCF client to read settings out of different config file?

Community
  • 1
  • 1
deostroll
  • 11,661
  • 21
  • 90
  • 161