Click here to Skip to main content
15,895,084 members
Articles / Programming Languages / XML

WCF Proxy Generation Options

Rate me:
Please Sign up or sign in to vote.
3.57/5 (5 votes)
11 Feb 2009CPOL7 min read 129.8K   3.6K   23  
An overview of a number of different ways of generating proxies for using WCF Services.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProxyGeneration;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace ProxyGenerationHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceProc();
        }

        private static void ServiceProc()
        {
            ServiceHost host = new ServiceHost(typeof(ProxyServ));
            try
            {
                Console.WriteLine("WCF Service: Starting Up");
                host.Opened += new EventHandler(host_Opened);
                host.Open();
                Console.WriteLine("Please press any key to close...");
                Console.ReadLine();
            }
            finally
            {
                if (host.State != System.ServiceModel.CommunicationState.Closed)
                {
                    host.Close();
                }
            }
        }

        private static void host_Opened(object sender, EventArgs e)
        {
            Console.WriteLine("WCF Service: Running");

            System.ServiceModel.ServiceHost host = (System.ServiceModel.ServiceHost)sender;
            StringBuilder detailBuilder = new StringBuilder();
            foreach (Uri baseAddress in host.BaseAddresses)
            {
                detailBuilder.AppendFormat("\r\nBase Address: {0}", baseAddress.ToString());
            }

            foreach (ServiceEndpoint endPoint in host.Description.Endpoints)
            {
                string address = endPoint.Address.ToString();
                string bindingName = endPoint.Binding.Name;
                detailBuilder.AppendFormat("\r\nEndpoint({0}): {1}", bindingName, address);
            }

            Console.WriteLine(detailBuilder.ToString());
        }
    }
}

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)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
Chris is a full time software developer in London, UK.
He has a BSc in computer science and is busy taking courses in the MCTS stream.

Comments and Discussions