Click here to Skip to main content
13,150,472 members (33,227 online)
Click here to Skip to main content

Stats

58.6K views
997 downloads
50 bookmarked
Posted 24 Apr 2008

Runtime Generated WCF Service Exposing .NET or COM Types

, 24 Apr 2008
A WCF service wrapper is generated at runtime around a .NET or COM type to expose its interface.
ConsoleClient.exe
DummyComInterop.exe
ServiceHostContainer.exe
ComponentCom.dll
ComponentNet.dll
ComponentNetBase.dll
ComponetNetBase2.dll
Interop.ComponentComLib.dll
WcfServiceHost.dll
ConsoleClient
Properties
Service References
Class1
configuration.svcinfo
Reference.svcmap
service.wsdl
Class1_PerCall
configuration.svcinfo
Reference.svcmap
service.wsdl
Class2
configuration.svcinfo
Reference.svcmap
service.wsdl
Class2_PerCall
configuration.svcinfo
Reference.svcmap
service.wsdl
DummyComInterop
Properties
ServiceHostContainer
Properties
WcfServiceHost
Properties
WcfServiceHost.csproj.user
ComponentCom
Class2.rgs
ComponentCom.def
ComponentCom.rgs
ComponentCom.vcproj.vspscc
ComponentComps.def
ComponentNet
Properties
ComponentNetBase
Properties
ComponetNetBase2
Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleClient.Class1;
using ConsoleClient.Class1_PerCall;
using ConsoleClient.Class2;
using ConsoleClient.Class2_PerCall;

namespace ConsoleClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\nACTION REQUIRED: Press any key to proceed after Services started...");
            Console.ReadKey();

            // Class1 per session
            Console.WriteLine("\n**** Class1 per session ****");
                       
            Class1Client c1 = new Class1Client();
            c1.set_Count(139);
            int n = 61;
            Console.WriteLine("{0} + {1} = {2}", c1.get_Count(), n, c1.Add(n));
            Console.WriteLine("{0} - {1} = {2}", c1.get_Count(), n, c1.Subtract(n));

            Console.WriteLine(c1.Concat("XXX "));
            Console.WriteLine(c1.Concat("YYY "));
            
            // Class2 per session
            Console.WriteLine("\n**** Class2 per session ****");

            Class2Client c2 = new Class2Client();
            string param1 = "AAA ";
            int param2 = 15;
            Console.WriteLine("{0}", c2.Method1(ref param1, ref param2));

            param1 = "BBB ";
            param2 = 5;
            Console.WriteLine("{0}", c2.Method1(ref param1, ref param2));

            param1 = "CCC ";
            param2 = 10;
            Console.WriteLine("{0}", c2.Method1(ref param1, ref param2));

            // Class1 per call
            Console.WriteLine("\n**** Class1 per call ****");
                        
            Class1_PerCallClient c1pc = new Class1_PerCallClient();
            c1pc.set_Count(139);
            n = 61;
            Console.WriteLine("{0} + {1} = {2}", c1pc.get_Count(), n, c1pc.Add(n));
            Console.WriteLine("{0} - {1} = {2}", c1pc.get_Count(), n, c1pc.Subtract(n));

            Console.WriteLine(c1pc.Concat("XXX "));
            Console.WriteLine(c1pc.Concat("YYY "));

            // Class2 per call
            Console.WriteLine("\n**** Class2 per call ****");
                       
            Class2_PerCallClient c2pc = new Class2_PerCallClient();
            param1 = "AAA ";
            param2 = 15;
            Console.WriteLine("{0}", c2pc.Method1(ref param1, ref param2));

            param1 = "BBB ";
            param2 = 5;
            Console.WriteLine("{0}", c2pc.Method1(ref param1, ref param2));

            param1 = "CCC ";
            param2 = 10;
            Console.WriteLine("{0}", c2pc.Method1(ref param1, ref param2));

            // Sleep to test ReceiveTimeout feature.
            int timeoutInSec = 30;
            Console.WriteLine("\n*** Sleeping for {0} sec to test \"receiveTimeout\" and then will proceed... ***\n", timeoutInSec);
            System.Threading.Thread.Sleep(timeoutInSec * 1000);
            
            // Class1 per session
            Console.WriteLine("\n**** Class1 per session ****");

            n = 61;
            try
            {
                Console.WriteLine("{0} + {1} = {2}", c1.get_Count(), n, c1.Add(n));
                Console.WriteLine("{0} - {1} = {2}", c1.get_Count(), n, c1.Subtract(n));

                Console.WriteLine(c1.Concat("XXX "));
                Console.WriteLine(c1.Concat("YYY "));
            }
            catch (Exception e)
            {
                Console.WriteLine("\nERROR: {0}.\nInnerException Message: {1}\n", e.Message, e.InnerException.Message);
            }

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Igor Ladnik
Software Developer (Senior)
Israel Israel


  • Nov 2010: Code Project Contests - Windows Azure Apps - Winner

  • Feb 2011: Code Project Contests - Windows Azure Apps - Grand Prize Winner



You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170924.2 | Last Updated 24 Apr 2008
Article Copyright 2008 by Igor Ladnik
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid