开发者

WCF 'sub main' not found

开发者 https://www.devze.com 2023-03-04 19:24 出处:网络
I must be losing my mind... After getting a test WCF hosted in a windows service, I\'m trying for another one (practice, practice, practice).

I must be losing my mind...

After getting a test WCF hosted in a windows service, I'm trying for another one (practice, practice, practice).

I created a WCF service library, added one function. Then created a Windows Service, and added my WCF to the project. Did the rest of the stuff located here (http://joefreeman.co.uk/blog/2010/03/creating-a-setup-project-for-a-windows-wcf-service-with-visual-studio/)

Now I'm getting this "Sub Mian was not found in [WCF app]" error when I try to build the solution.

I didn't think WCF projects required a Sub Main as they are service开发者_如何学Gos and not applications. What am I doing wrong? I didn't have a sub main in my last project. Any ideas?


For others who are looking for the same answer I was...

Created a service in VB.NET (VS2010), and was getting the same error listed above...

'Sub Main' was not found in 'SERVICENAME.Service1'.

In VB.NET, VS2010 created a "Service1.Designer.vb" file for me automatically. Inside of that file was:

    Shared Sub Main()
    Dim ServicesToRun() As System.ServiceProcess.ServiceBase

    ' More than one NT Service may run within the same process. To add
    ' another service to this process, change the following line to
    ' create a second service object. For example,
    '
    '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
    '
    ServicesToRun = New System.ServiceProcess.ServiceBase() {New SERVICENAME}

    System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub

To resolve this, right-click your solution name in the solution explorer, go to the "Application" tab, and pick "Sub Main" as your Startup object in the "Startup object" drop-down box. Recompile.

Granted, the file names and structure will be different in C#, but the idea is that Visual Studio put the Main procedure SOMEWHERE, and it hopefully should already know where it is.


The WCF service itself doesn't need a Sub Main, but your Windows Service does.

Compare against your previously built, working Windows Service.

edit: using C#, when I create a new project using the Windows Service template, I get the following initial code in a Program.cs file (static void Main is your Sub Main). I'd be very surprised if you don't also have this in your Windows Service.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()


Check you haven't accidentally changed the Application type to something stupid like "windows forms app", hit the properties of the project and make sure it's on "class library".

0

精彩评论

暂无评论...
验证码 换一张
取 消