문제

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