C# wcf void main

Posted on 2011-10-10
Last Modified: 2012-05-12
I have a C# WCF project (vs2010u) and I need to be able to point to a start up method.  Most applications have static void main, but I don't see that here.

How can I get a WCF service to automatically execute a particular method on startup?

Also, is there a close event that I can have it respond to as well?


Question by:hpdvs2
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    How are you hosting the service--in IIS or in a self-hosted setup (e.g. console application or windows service)?
    LVL 8

    Author Comment

    I've been using debug mode, in VS2010 so far, just now paying attention to the fact it was going through IIS.  However, I'm planning on building this for a console app.  I'm guessing that the console app will call it on its void main.
    LVL 74

    Accepted Solution

    I've been using debug mode, in VS2010 so far
    If by that you mean you created the service, and only the service (i.e. no other project like a Console project), then you are simulating running the app on IIS, albeit using VS' built-in web server Cassini.

    However, I'm planning on building this for a console app.  I'm guessing that the console app will call it on its void main.
    That depends on what you mean. If you mean you are creating a Console app to host the application (as opposed to using IIS), then yes your console app will have a main and inside that function you will call code to start your service. If instead you mean that you will be creating an app that will be consuming your service (i.e. using its function calls), then that is an entirely separate application.

    See if this link clears up your confusion:
    LVL 8

    Author Closing Comment

    I'll add this line:  I didn't realize some of the difficulties in producing the console app version.  The first I tried was windows service, which was a huge pain.  Then I tried console app from, and then called the initializer from the main() in the console app.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Title # Comments Views Activity
    c# vs2013 corrupt .dll 4 34
    Delegate in C# 3 35 mvc C# 2 27
    Cast Bit From SQL To 0 or 1 In .NET and not True / False 4 26
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now