Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/");
            ServiceHost selfHost = new WebServiceHost(typeof(MonitorService), baseAddress);

            try
            {
                // Step 3 Add a service endpoint.
                var t = new WebHttpBinding();

                selfHost.AddServiceEndpoint(typeof(IMonitorService), t, "test");
                WebHttpBehavior whb = new WebHttpBehavior();

                // Step 4 Enable metadata exchange.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;

                selfHost.Description.Behaviors.Add(smb);

                // Step 5 Start the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
 static void Main(string[] args)
 {
     WebServiceHost webHost = null;
     try
     {
         webHost = new WebServiceHost(typeof(CarRentalService), new Uri("http://localhost:1234"));
         webHost.Open();
         Console.WriteLine("Web service host is open...");
         Console.ReadLine();
     }
     catch(Exception ex)
     {
         if (webHost != null) webHost.Abort();
         Console.WriteLine(ex.ToString());
     }
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(RestService), new Uri(RestUri));
            try
            {
                host.AddServiceEndpoint(typeof(IRestService), new WebHttpBinding(), "");
                host.Open();

                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();

                host.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("An exception occurred: {0}", e.Message);
                host.Abort();
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                host.Open();
                using (ChannelFactory<IService> cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:8000"))
                {
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

                    IService channel = cf.CreateChannel();

                    object s;

                    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
                    s = channel.EchoWithGet("Hello, world");
                    Console.WriteLine("   Output: {0}", s);

                    Console.WriteLine("");
                    Console.WriteLine("This can also be accomplished by navigating to");
                    Console.WriteLine("http://localhost:8000/EchoWithGet?s=Hello, world!");
                    Console.WriteLine("in a web browser while this sample is running.");

                    Console.WriteLine("");

                    Console.WriteLine("Calling EchoWithPost via HTTP POST: ");
                    s = channel.EchoWithPost("Hello, world");
                    Console.WriteLine("   Output: {0}", s);
                    Console.WriteLine("");
                }

                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();

                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Ejemplo n.º 5
0
 static void Main(string[] args)
 {
     var host = new System.ServiceModel.Web.WebServiceHost(typeof(EvalService));
      try
      {
     host.Open();
     foreach (var endpoint in host.Description.Endpoints)
     {
        Console.WriteLine(endpoint.Address.ToString());
     }
     Console.WriteLine("EvalService is up and running");
     Console.ReadLine();
     host.Close();
      }
      catch (Exception e)
      {
     Console.WriteLine(e);
     host.Abort();
      }
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(EvalService));

            try
            {
                host.Open();

                PrintServiceInfo(host);

                Console.WriteLine();
                Console.WriteLine("Press [ENTER] to shutdown the server...");
                Console.ReadLine();

                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                host.Abort();
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:9876/");

            //WebServiceHost svcHost = new WebServiceHost(typeof(AATodo.CalcService), baseAddress);
            WebServiceHost svcHost = new WebServiceHost(new AATodoService(), baseAddress);

            try
            {
                svcHost.Open();

                Console.WriteLine("Service is running at " + baseAddress);
                Console.WriteLine("Press enter to quit...");
                Console.ReadLine();

                svcHost.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                svcHost.Abort();
            }
        }
Ejemplo n.º 8
0
        public TestService(Type serviceType)
        {
            for (int i = 0; i < 100; i++)
            {
                int hostId = Interlocked.Increment(ref s_lastHostId);
                _serviceUri = new Uri("http://" + Environment.MachineName + "/Temporary_Listen_Addresses/MongoTestService" + hostId.ToString() + "/");
                _host = new WebServiceHost(serviceType, _serviceUri);
                try
                {
                    _host.Open();
                    break;
                }
                catch (Exception)
                {
                    _host.Abort();
                    _host = null;
                }
            }

            if (_host == null)
            {
                throw new InvalidOperationException("Could not open a service even after 100 tries.");
            }
        }
Ejemplo n.º 9
0
		private bool SetupWebServiceSilverlight()
		{
			Uri webServiceAddress = new Uri("http://localhost:" + SLWCFPort.ToString() + "/");
			m_webHostSilverlight = new WebServiceHost(typeof(WebServiceSilverlight), webServiceAddress);
			try
			{
				WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
				ServiceEndpoint endpoint = m_webHostSilverlight.AddServiceEndpoint(typeof(IPolicyRetriever), binding, "");
				m_webHostSilverlight.SetEndpointAddress(endpoint, "");
				m_webHostSilverlight.Open();
			}
			catch (CommunicationException ex)
			{
				Console.WriteLine("An exception occurred: {0}", ex.Message);
				m_webHostSilverlight.Abort();
				return false;
			}

			return true;
		}
Ejemplo n.º 10
0
		private bool SetupWebService()
		{
			Uri webServiceAddress = new Uri("http://localhost:" + WCFPort.ToString() + "/SEServerExtender/Web/");
			m_webHost = new WebServiceHost(typeof(WebService), webServiceAddress);
			try
			{
				//WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
				//binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
				//binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
				//ServiceEndpoint endpoint = m_webHost.AddServiceEndpoint(typeof(IWebServiceContract), binding, "WebService");
				//m_webHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
				//m_webHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new UserNameValidator();
				EnableCorsBehavior ecb = new EnableCorsBehavior();
				m_webHost.Description.Behaviors.Add(ecb);
				m_webHost.Open();
			}
			catch (CommunicationException ex)
			{
				Console.WriteLine("An exception occurred: {0}", ex.Message);
				m_webHost.Abort();
				return false;
			}

			return true;
		}
Ejemplo n.º 11
0
 private static void Main(string[] args)
 {
     var address = new Uri("http://localhost:8000/FeedService/");
     var svcHost = new WebServiceHost(typeof (FeedService), address);
     try {
         svcHost.Open();
         Console.WriteLine("Service is running");
         Console.WriteLine("Open browser at http://localhost:8000/FeedService/GetFeeds?format={atom/rss}");
         Console.WriteLine("Press <ENTER> to quit...");
         Console.ReadLine();
         svcHost.Close();
     }
     catch (CommunicationException ce) {
         Console.WriteLine("An exception occurred: {0}", ce.Message);
         svcHost.Abort();
     }
 }