Вопрос

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?

Это было полезно?

Решение 2

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" %>

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top