Ejemplo n.º 1
0
 public void Close(TimeSpan closeTimeout)
 {
     if (Interlocked.Exchange(ref _disposeSignaled, 1) != 0)
     {
         return;
     }
     _disposed = true;
     _operationPending.WaitOne(closeTimeout);
     if (_context != null)
     {
         _context.Dispose();
         _context = null;
     }
     if (_client != null)
     {
         _client.Dispose();
         _client = null;
     }
 }
Ejemplo n.º 2
0
        //TODO: split RpcProxyRouter and RpcCallbackProxy
        public ClientRuntime(string address, ServiceEndpoint endpoint, bool callback = false, InstanceContext context = null, Guid customUuid = default(Guid), Type generatedProxyType = null)
        {
            _endpoint      = endpoint;
            _binding       = endpoint._binding;
            _serializer    = _binding.Serializer;
            _typeOfService = endpoint._contractType;
            _context       = context;
            if (_context != null && _context._useSynchronizationContext)
            {
                _syncContext = SynchronizationContext.Current;
            }
            _generatedProxyType = generatedProxyType;

            _address = address;

            _operations = DispatchTableFactory.GetOperations(_typeOfService);


            _uuid = EndpointMapper.CreateUuid(_address, _typeOfService);
            if (customUuid != Guid.Empty) // callback proxy
            {
                _uuid = customUuid;
            }

            var serviceContract = AttributesReader.GetServiceContract(_typeOfService);

            //TODO: null check only for duplex callback, really should always be here
            if (serviceContract != null && serviceContract.SessionMode == SessionMode.Required)
            {
                _session = Guid.NewGuid().ToString();
            }
            //TODO: allow to be initialized with pregenerated proxy
            var realProxy = new RpcRealProxy(_typeOfService, this, _endpoint, _encoder);

            _remote = realProxy.GetTransparentProxy();
            _client = RpcRequestReplyChannelFactory.CreateClient(_binding, _uuid, _address);
            foreach (var behavior in _endpoint.Behaviors)
            {
                behavior.ApplyClientBehavior(_endpoint, this);
            }
        }