using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Microsoft.ServiceBus;
using System.ServiceModel.Description;

namespace HelloServiceBus
{
    [ServiceContract]
    public interface IHelloServiceBus
    {
        [OperationContract]
        string SayHello(string name);
    }

    public class HelloServiceBus : IHelloServiceBus
    {
        public string SayHello(string name)
        {
            string greeting = string.Format("Hello {0}!", name);
            Console.WriteLine("Returning: {0}", greeting);
            return greeting;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("**** Service ****");
            ServiceHost host = new ServiceHost(typeof(HelloServiceBus));

            //ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
            
            ServiceRegistrySettings settings = new ServiceRegistrySettings();
            settings.DiscoveryMode = DiscoveryType.Public;
            foreach(ServiceEndpoint se in host.Description.Endpoints)
                se.Behaviors.Add(settings);

            host.Open();

            Console.WriteLine("Press [Enter] to exit");
            Console.ReadLine();

            host.Close();
        }
    }
}
