Exemplo n.º 1
0
    public static void Test()
    {
        string         baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        WebServiceHost host        = new WebServiceHost(typeof(Service), new Uri(baseAddress));

        host.Open();
        Console.WriteLine("Host opened");
        WebChannelFactory <ITest> factory = new WebChannelFactory <ITest>(new Uri(baseAddress));
        ITest proxy = factory.CreateChannel();

        using (new OperationContextScope((IContextChannel)proxy))
        {
            WebOperationContext.Current.OutgoingRequest.ContentType = "text/xml";
            Console.WriteLine(proxy.Process());
        }
        using (new OperationContextScope((IContextChannel)proxy))
        {
            WebOperationContext.Current.OutgoingRequest.ContentType = "application/xml";
            Console.WriteLine(proxy.Process());
        }
        ((IClientChannel)proxy).Close();
        factory.Close();
        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
Exemplo n.º 2
0
 public void Dispose()
 {
     ServiceClient = null;
     ChannelFactory.Close();
     ChannelFactory = null;
     if (_autoUpdateTimerSync != null)
     {
         _autoUpdateTimerSync.Stop();
         _autoUpdateTimerSync.Dispose();
     }
     _autoUpdateTimerSync = null;
     if (_autoUpdateTimerAsync != null)
     {
         _autoUpdateTimerAsync.Stop();
         _autoUpdateTimerAsync.Dispose();
     }
     _autoUpdateTimerAsync = null;
     _token = null;
 }
Exemplo n.º 3
0
		public IAzureServiceManagement CreateChannel()
		{
			// long lock, but should in practice never be accessed
			// from two threads anyway (just a safeguard) and this way
			// we avoid multiple sync monitor enters per call
			lock (_sync)
			{
				if (_factory != null)
				{
					switch (_factory.State)
					{
						case CommunicationState.Closed:
						case CommunicationState.Closing:
							// TODO: consider reusing the factory
							_factory = null;
							break;
						case CommunicationState.Faulted:
							_factory.Close();
							_factory = null;
							break;
					}
				}

				if (_factory == null)
				{
					var binding = new WebHttpBinding(WebHttpSecurityMode.Transport);
					binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

					_factory = new WebChannelFactory<IAzureServiceManagement>(binding, new Uri(ApiConstants.ServiceEndpoint));
					_factory.Endpoint.Behaviors.Add(new ClientOutputMessageInspector());
					_factory.Credentials.ClientCertificate.Certificate = _certificate;
				}

				return _factory.CreateChannel();
			}
		}
Exemplo n.º 4
0
 public void Dispose()
 {
     ServiceClient = null;
     ChannelFactory.Close();
     ChannelFactory = null;
 }