Пример #1
0
    // Host the service within this EXE console application.
    public static void Main()
    {
      // Create a ServiceHost for the CalculatorService type and use
      // the base address from config.
      ServiceHost hostDefault = new 
       ServiceHost(typeof(CalculatorService));
      
      TimeSpan closeTimeout = hostDefault.CloseTimeout;
      
      TimeSpan openTimeout = hostDefault.OpenTimeout;


      ServiceAuthorizationBehavior authorization =
	      hostDefault.Authorization;

      ServiceCredentials credentials =
				      hostDefault.Credentials;

      ServiceDescription description = 
			  hostDefault.Description;


      int manualFlowControlLimit = 
			  hostDefault.ManualFlowControlLimit;


      NetTcpBinding portsharingBinding = new NetTcpBinding();
      hostDefault.AddServiceEndpoint(
	typeof( CalculatorService ),
	portsharingBinding,
	"net.tcp://localhost/MyService" );


      int newLimit = hostDefault.IncrementManualFlowControlLimit(100);
      
      using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
      {
        try
        {
          // Open the ServiceHost to start listening for messages.
          serviceHost.Open();
          // The service can now be accessed.
          Console.WriteLine("The service is ready.");
          Console.WriteLine("Press <ENTER> to terminate service.");
          Console.ReadLine();

          // Close the ServiceHost.
          serviceHost.Close();
        }
        catch (TimeoutException timeProblem)
        {
          Console.WriteLine(timeProblem.Message);
          Console.ReadLine();
        }
        catch (CommunicationException commProblem)
        {
          Console.WriteLine(commProblem.Message);
          Console.ReadLine();
        }
      }
    }
Пример #2
0
        public void ShouldPublishToPublisherAndGetNotificationBack()
        {
            ServiceHost hostDefault = new
   ServiceHost(typeof(Subscriber));

            TimeSpan closeTimeout = hostDefault.CloseTimeout;

            TimeSpan openTimeout = hostDefault.OpenTimeout;


            ServiceAuthorizationBehavior authorization =
                hostDefault.Authorization;

            ServiceCredentials credentials =
                            hostDefault.Credentials;

            ServiceDescription description =
                    hostDefault.Description;


            int manualFlowControlLimit =
                    hostDefault.ManualFlowControlLimit;


            NetTcpBinding portsharingBinding = new NetTcpBinding();
            hostDefault.AddServiceEndpoint(
          typeof(ISubscriber),
          portsharingBinding,
          "net.tcp://localhost/MyService");


            int newLimit = hostDefault.IncrementManualFlowControlLimit(100);

            using (ServiceHost serviceHost = new ServiceHost(typeof(Subscriber)))
            {
                try
                {
                    // Open the ServiceHost to start listening for messages.
                    serviceHost.Open();
                    // The service can now be accessed.
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.ReadLine();

                    // Close the ServiceHost.
                    serviceHost.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                    throw ex;
                }
            }

            using (PublisherClient target = new PublisherClient())
            {
                string message = "Test message";
                string activityId = "Test activity";
                target.Publish(message, activityId);
            }
        }