private void OnRemoteSideDisconnected(RemoteSideIDType remoteSideID) { if (RemoteSideDisconnected != null) { RemoteSideDisconnected(this, new RemoteSideDisconnectedEventArgs(remoteSideID)); } }
public TResult ExecuteOnRemoteSide <TResult>(RemoteSideIDType remoteSideID, RemoteOperationDescriptor rso) { ThrowIfNotInitialized(); TResult ret = (TResult)ExecuteOnRemoteSideInternal(remoteSideID, rso); return(ret); }
protected virtual void DisconnectRemoteSide(RemoteSideIDType remoteID, IRemoteSideCommunicationContract serviceContract) { remoteSideIDsByCommunicationContractDict.Remove(serviceContract); communicationContractsByRemoteSideIDDict.Remove(remoteID); OnRemoteSideDisconnected(remoteID); }
private void OnRemoteSideConnected(RemoteSideIDType remoteSideID) { System.Diagnostics.Debug.WriteLine("New connection: {0}!", remoteSideID.ToString()); if (RemoteSideConnected != null) { RemoteSideConnected(this, new RemoteSideConnectedEventArgs(remoteSideID)); } }
public RemoteSideDisconnectedEventArgs(RemoteSideIDType remoteID) { if (remoteID == null) { throw new ArgumentNullException("remoteID"); } this.RemoteID = remoteID; }
protected virtual object ExecuteOnRemoteSideInternal(RemoteSideIDType remoteSideID, RemoteOperationDescriptor rso) { object ret = null; if (remoteSideID == null) { throw new ArgumentNullException("remoteSideID"); } if (rso == null) { throw new ArgumentNullException("rso"); } // find appropriate client IRemoteSideCommunicationContract contract = null; bool lockTaken = false; try { syncRoot.Enter(ref lockTaken); communicationContractsByRemoteSideIDDict.TryGetValue(remoteSideID, out contract); } finally { if (lockTaken) { syncRoot.Exit(); } } if (contract != null) { RemoteRequest req = remoteOperationHandler.CreateRequest(rso); req.RemoteID = remoteSideID; RemoteResponse resp = null; try { RequestToRemoteSideStarted(remoteSideID, rso); resp = contract.ExecuteRequest(req); } finally { RequestToRemoteSideFinished(remoteSideID, rso); } ret = remoteOperationHandler.HandleResponse(resp); } else { throw new InvalidOperationException(String.Format("Unknown remote side id: {0}", remoteSideID)); } return(ret); }
public WCFServiceClient(InstanceContext instanceContext, Binding binding, EndpointAddress remoteAddress) : base(instanceContext, binding, remoteAddress) { this.ID = RemoteSideIDType.Parse(Guid.NewGuid().ToString()); ((ICommunicationObject)base.Channel).Closed += new EventHandler(ClientServiceContractClient_StateChanged); ((ICommunicationObject)base.Channel).Closing += new EventHandler(ClientServiceContractClient_StateChanged); ((ICommunicationObject)base.Channel).Faulted += new EventHandler(ClientServiceContractClient_StateChanged); ((ICommunicationObject)base.Channel).Opened += new EventHandler(ClientServiceContractClient_StateChanged); ((ICommunicationObject)base.Channel).Opening += new EventHandler(ClientServiceContractClient_StateChanged); }
public virtual void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } try { reader.ReadStartElement(); this.RemoteID = RemoteSideIDType.Parse(reader.ReadElementString("RemoteID")); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; } }
public WCFServiceHost(IDIContainer diContainer, IRemoteSideCommunicationContract clientServiceContractInstance, Uri clientServiceAddress) : base(clientServiceContractInstance, clientServiceAddress) { this.ID = RemoteSideIDType.Parse(Guid.NewGuid().ToString()); this.diContainer = diContainer; this.clientServiceContractInstance = clientServiceContractInstance; cm = diContainer.GetLazyBoundInstance <IWCFConfigManager>(); ApplyConfiguration(); this.AddServiceEndpoint( ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), String.Concat(new Uri(cm.Value.ClientServiceAddress).OriginalString, "/mex")); this.Closed += new EventHandler(clientServiceHost_StateChanged); this.Closing += new EventHandler(clientServiceHost_StateChanged); this.Faulted += new EventHandler(clientServiceHost_StateChanged); this.Opened += new EventHandler(clientServiceHost_StateChanged); this.Opening += new EventHandler(clientServiceHost_StateChanged); }
protected virtual void RemoteRequestFinished(RemoteSideIDType remoteSideID, RemoteRequest request) { }
protected virtual void RemoteRequestStarted(RemoteSideIDType remoteSideID, RemoteRequest request) { }
protected virtual void RemoteSideReconnected(RemoteSideIDType remoteSideID) { }
protected virtual void KnownRemoteSideRequest(RemoteSideIDType remoteSideID) { }
protected virtual void NewRemoteSideConnected(RemoteSideIDType remoteSideID) { }
public virtual RemoteResponse ExecuteRequest(RemoteRequest request) { ThrowIfNotInitialized(); if (request == null) { throw new ArgumentNullException("request"); } RemoteResponse ret = null; RemoteSideIDType remoteID = request.RemoteID; if (remoteID == null) { throw new InvalidOperationException("Remote call without remote side id!"); //LOCSTR } var wrapper = remoteSide; IRemoteSideCommunicationContract currentContract = wrapper.GetCurrentRemoteSideCommunicationContract(); try { bool isNewRemoteSide = false; bool lockTaken = false; try { syncRoot.Enter(ref lockTaken); RemoteRequestStarted(remoteID, request); IRemoteSideCommunicationContract lastKnownContract = null; if (communicationContractsByRemoteSideIDDict.TryGetValue(remoteID, out lastKnownContract)) { // known client comes in again if (lastKnownContract != currentContract) { communicationContractsByRemoteSideIDDict[remoteID] = currentContract; remoteSideIDsByCommunicationContractDict.Remove(lastKnownContract); remoteSideIDsByCommunicationContractDict.Add(currentContract, remoteID); wrapper.Closed += new EventHandler(Channel_Closed); wrapper.Faulted += new EventHandler(Channel_Faulted); RemoteSideReconnected(remoteID); //Log.Debug("Client {0} reconnected.", remoteID.ToString()); //LOCSTR System.Diagnostics.Debug.WriteLine("Client {0} reconnected.", remoteID.ToString()); //LOCSTR } KnownRemoteSideRequest(remoteID); } else { wrapper.Closed += new EventHandler(Channel_Closed); wrapper.Faulted += new EventHandler(Channel_Faulted); remoteSideIDsByCommunicationContractDict.Add(currentContract, remoteID); communicationContractsByRemoteSideIDDict.Add(remoteID, currentContract); NewRemoteSideConnected(remoteID); isNewRemoteSide = true; } } finally { if (lockTaken) { syncRoot.Exit(); } } if (isNewRemoteSide) { OnRemoteSideConnected(remoteID); } // process request ret = remoteOperationHandler.ExecuteRequest(request, typeof(RemoteCallableTypeAttribute), typeof(RemoteCallableFuncAttribute)); } finally { RemoteRequestFinished(remoteID, request); } return(ret); }
protected virtual void RequestToRemoteSideFinished(RemoteSideIDType remoteSideID, RemoteOperationDescriptor rso) { }
public void ExecuteOnRemoteSide(RemoteSideIDType remoteSideID, RemoteOperationDescriptor rso) { ThrowIfNotInitialized(); ExecuteOnRemoteSideInternal(remoteSideID, rso); }
protected virtual void RemoteSideFaulted(RemoteSideIDType remoteID) { }