//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); } }
internal void Open(ConcurrencyMode concurrency) { _concurrency = concurrency; //Action open = delegate { try { if (_host == null) { RpcExecuteHandler onExecute = delegate(IRpcCallInfo client, byte[] arg) { if (_concurrency == ConcurrencyMode.Single) { //lock (this) //{ _operationPending.Reset(); try { return(Invoke(client, _endpoint._contractType, arg)); } finally { _operationPending.Set(); } //} } if (_concurrency == ConcurrencyMode.Multiple) { //BUG: need have collection of operations because second operation rewrites state of first _operationPending.Reset(); try { return(Invoke(client, _endpoint._contractType, arg)); } finally { _operationPending.Set(); } } throw new NotImplementedException( string.Format("ConcurrencyMode {0} is note implemented", _concurrency)); }; _host = RpcRequestReplyChannelFactory.CreateHost(_endpoint._binding, _endpoint._address, _endpoint._uuid); _host.OnExecute += onExecute; _host.StartListening(); } //_opened.Set(); } catch (Exception ex) { bool handled = ExceptionHandler.AlwaysHandle.HandleException(ex); if (!handled) { throw; } } }; //Tasks.Factory.StartNew(open); //_opened.WaitOne(); }