HowTo: InProc WCF

Well I wrote in the last post about how to make an in-process WCF host.

In this post it is just the keep-it-simple and only about inproc WCF

Get the code her: http://www.box.net/shared/zqk2ltfi1i.

The service WcfServiceMan.cs:

using System.ServiceModel; //ServiceContract

    [ServiceContract]
    interface IWcfServiceMan
    {
        [OperationContract]
        void DoWork();
    }

    public class WcfServiceMan : IWcfServiceMan
    {
        public void DoWork()
        {
            Console.WriteLine("Inside DoWork()");
        }
    }

The host and client Program.cs:

using ServiceModelEx; //InProcFactory

        static void Main(string[] args)
        {
            Console.WriteLine("*** Server ***");

            IWcfServiceMan svc = null;
            try
            {
                //This one-liner executes the service in its own thread and lets it listen over a named pipe.
                svc = InProcFactory.CreateInstance<WcfServiceMan, IWcfServiceMan>();

                svc.DoWork();

                Console.WriteLine("Press <Enter> to terminate the Host application.");
                Console.ReadLine();
            }
            finally
            {
                if (svc != null)
                {
                    InProcFactory.CloseProxy(svc);
                }
            }
        }

Note: You don’t need anything inside the app.config, which means you don’t need that file! WCF configures itself inside the InProcFactory both to be a service that listens over a named pipe and it delivers a proxy, which can communicate over that pipe. All dynamicly done (without the <system.serviceModel> in app.config).

Source code for IDesign’s InProcFactory can freely be downloaded from: http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=11#WCFEssentials

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: