1

I have a working console application where all the adresses and configuration are in a config file. But when I try to move this code to a WCF Service Application i get all kinds of errors.

class Program
{
    static void Main(string[] args)
    {

        WebServiceHost host = new WebServiceHost(typeof(ImageService));
        host.Open();

        Console.WriteLine("Service up");
        Console.ReadLine();

        host.Close();
    }
}

The problem is that the WCF service application starts automatically and has no main method, like the console app. How do I define the WCF service to start a WebServiceHost when no main method exists?

Zeezer
  • 1,503
  • 2
  • 18
  • 33
  • Do you want to self-host this WCF service? When you say your project connects to a Azure Service bus what is it. Are you trying to perform a call to your WCF service that internally calls the Azure Service Bus? – Rajesh Mar 20 '13 at 16:29
  • Im trying to set up a service which could be called from Azure Service bus relay using REST. This works fine with a service initialised like the one above. Of course I dont want to use a console app, which im using now, so I want to convert this to a WCF service hosted on IIS. – Zeezer Mar 20 '13 at 19:03

2 Answers2

0

You have to create your own service by inheriting from the ServiceBase class. Override the OnStart() method and open your WCF service in the implementation. Override the OnStop() method and close your WCF service in the implementation.

flayn
  • 5,272
  • 4
  • 48
  • 69
  • How is this done? I have tried inheriting from ServiceBase and override with OnStart() in the example above, but something more must be added, the OnStart() method is never called – Zeezer Mar 20 '13 at 14:23
  • Create an instance of your service and call OnStart() – flayn Mar 20 '13 at 15:44
  • What kind of project to you have now? – flayn Mar 20 '13 at 15:45
  • Create an instance? No, I want WCF to be hosted on IIS, so i cant create an instance of my service and call it. How should i create something when there is no main method? – Zeezer Mar 20 '13 at 15:49
  • My project connects a WCF service to azure service bus. When using the console application(with WebServiceHost) and the same config everything works fine. But when using WCF (same config settings) i get "AddressFilter mismatch at the EndpointDispatcher" – Zeezer Mar 20 '13 at 15:54
  • You should maybe add the information that you want to host in IIS to your question. This is quite important. For IIS you have to create a svc file. – flayn Mar 20 '13 at 19:08
  • http://blah.winsmarts.com/2008-4-Host_a_WCF_Service_in_IIS_7_-and-amp;_Windows_2008_-_The_right_way.aspx – flayn Mar 20 '13 at 19:08
  • But the problem is not related to IIS. At the moment im deploying it using visual studio. The problem is that I get adress filter mismatch because I cant declare a WebServiceHost in WCF correctly. – Zeezer Mar 20 '13 at 19:40
0

I found a very easy solution to this problem. In order to tell WCF to use webservice instead, all that is needed is to add this to the .svc file

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

Somehow I couldent open this file in Visual Studio, so I navigated to the project folder and opened it using notepad. My service .svc-file looks like this:

<%@ ServiceHost Language="C#" Debug="true" Service="MyNamespace.Service1" CodeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Zeezer
  • 1,503
  • 2
  • 18
  • 33