Question

I have a WCF Console Application with the following app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netNamedPipeBinding>
        <binding name="namedPipeBindingConfig" maxBufferPoolSize="268435456" maxBufferSize="16777216" maxReceivedMessageSize="16777216" />
      </netNamedPipeBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="serviceBehavior" name="MyTestNamespace.MyTestClassService">
        <endpoint address="net.pipe://localhost/MyService"
          binding="netNamedPipeBinding" bindingConfiguration="namedPipeBindingConfig"
          name="NamedPipeBinding" contract="MyTestNamespace.IMyTestContract" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

I am hosting it as a console app (interface, implementation and hosting class all in a single project), basically doing this:

ServiceHost host = new ServiceHost(typeof(MyTestClassService));
host.Open();

I run from command prompt "C:\SomePath\>RunMyService.exe" and it starts and works great. Now, I am planning to host this in IIS 7 and I did not find any good examples on how to get this (console application specifically) deployed there. Few questions I have are:

1) Do I need to "Add website" or "Add Application" in IIS and put my files there ?

2) Will I be needing a .svc file ? If yes, what must it contain and how do I tell it to start this console app.

3) Will this console app run inside IIS ? How does this work ?

Was it helpful?

Solution

Yes, you'll need to define a website in IIS in order to host your service in IIS. Also, you won't actually be running your console application in this configuration. In other words, the Program.Main function will never be called. Instead, IIS will load your MyTestClassService directly using its own ServiceHost implementation.

Although it is probably possible to use your console app binary with IIS (I say probably because I've never actually done this, but it should technically be possible), it might make more sense for you to move your service implementation code into a separate class library project. You can then reference the class library project from your ServiceHost console app and from IIS. This will be less confusing to other developers. In any case you must place the binary that contains your service interface and service definition into the bin directory of the website on which you will be hosting the service.

The configuration that currently resides in your app.config file will have to be moved to the web.config file of your website, and you'll have to use a different binding, since IIS doesn't support net.pipe.

You don't have to use an .svc file; you can use configuration based activation if you prefer. This would allow you to set up an empty website with only a web.config file that will host your service.

The main point is that you won't be hosting a console app, you'll be hosting a service. Right now your console app acts as a service host; when you reconfigure IIS will take that role. In order to find more resources, simply look for information about hosting WCF on IIS; the fact that you're currently hosting with ServiceHost in a console app is irrelevant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top