private void button1_Click(object sender, EventArgs e) { string address = textBox1.Text; if (!address.StartsWith("http://")) { address = "http://" + textBox1.Text; } int port = (int)numericUpDown1.Value; HttpClientChannel channel = null; try { channel = new HttpClientChannel(); ChannelServices.RegisterChannel(channel, false); RemotingObject remotingObject = (RemotingObject)Activator.GetObject(typeof(RemotingObject), address + ":" + port.ToString() + "/Remoting"); listBox1.Items.Add("Połączenie: " + address + ":" + port.ToString() + "/Remoting"); listBox1.Items.Add(remotingObject.Test()); ChannelServices.UnregisterChannel(channel); listBox1.Items.Add("Połączenie zakończone"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Błąd"); listBox1.Items.Add("Połączenie przerwane"); ChannelServices.UnregisterChannel(channel); } }
private void CreateNewRemotingObject(string variableName, Type t) { //服务器获取远程对象 _dataObject = new RemotingObject(variableName, t); ObjRef objRef = RemotingServices.Marshal(_dataObject, _dataObject.Name); }
private void Connect() { for (int i = 0; i < this.Retry; i++) { try { //获取代理 _dataObject = (RemotingObject)Activator.GetObject(typeof(RemotingObject), string.Format("tcp://{0}:{1}/{2}", _config.ConnectedIP, _config.ConnectedPort, _config.Name)); bool t = _dataObject == null; //订阅事件 (Remoting类库的限制,必须由另一个类库来执行客户端的事件) wrapper = new ClientEventWrapper(); _dataObject.DataUpdatedEvent += new RemotingObject.RemotingDelegate(wrapper.TriggerAtServerSwapEvent); wrapper.SwapSubscribeAtClient += new RemotingObject.RemotingDelegate(OnDataReceiving); _dataObject.DisconnectNotifier += new RemotingObject.ServerDisconnectDelegate(wrapper.NotifyDisconnection);; wrapper.ServerDisconnect += ServerDisconnect; this.Connected = true; return; } catch (Exception ex) { if (Marshal.GetHRForException(ex) == -2147467259) { //-2147467259 由于目标计算机积极拒绝,无法连接。 continue; } else { throw ex; } } } throw new Exception("连接失败,请检查连线配置"); }
public void RemoveVariable(string variableName) { _dataObject = Variables.Find(x => x.Name == variableName); _dataObject.NotifyServerDisconnection(); Variables.Remove(_dataObject); }
private void GrdMain_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { DataRowView drvSelect = this.grdMain.Rows[e.RowIndex].DataBoundItem as DataRowView; long lCardID = drvSelect["CardID"] == DBNull.Value ? 0 : Convert.ToInt64(drvSelect["CardID"]); if (lCardID > 0) { string strActionType = "ActionType=" + (int)enActionType.CardEdit; string strIpAddress = "Url=" + RemotingObject.GetIPAddress(); string strCardID = "CardID=" + lCardID; string strPath = Path.Combine(Application.StartupPath, "CardMain", "LB.CardMain.exe"); Process proc = Process.Start(strPath, strActionType + " " + strIpAddress + " " + strCardID); if (proc != null) { proc.WaitForExit(); } LoadDataSource(); } } } catch (Exception ex) { LB.WinFunction.LBCommonHelper.DealWithErrorMessage(ex); } }
static void Main(string[] args) { // 创建一个IPC信道。 IpcChannel channel = new IpcChannel(); // 注册这个信道。 ChannelServices.RegisterChannel(channel, false); // 注册一个远程对象的客户端代理. WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(typeof(RemotingObject), "ipc://TestChannel/RemoteObject.rem"); RemotingConfiguration.RegisterWellKnownClientType(remoteType); RemotingObject service = new RemotingObject(); Console.WriteLine("The client is invoking the remote object."); Console.WriteLine("The remote object has been called {0} times.", service.GetCount()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("called {0} times.", service.GetCount()); Console.WriteLine("-------------------------------------------"); Console.WriteLine("called {0} times.", service.GetCount()); Console.ReadLine(); }
/// <summary> /// 初始化 /// </summary> private void Initialize() { //设置反序列化级别 BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider(); serverProvider.TypeFilterLevel = TypeFilterLevel.Full;//支持所有类型的反序列化,级别很高 IDictionary idic = new Dictionary <string, string>(); idic["name"] = "serverHttp"; idic["port"] = "8022"; _channel = new HttpChannel(idic, clientProvider, serverProvider); _remotingObject = new RemotingObject(); }
public static void DisconnectIpc(bool unregister = true) { if (unregister && RemotingObject != null) { RemotingObject.UnregisterCallbackClient(); } if (unregister && PipeFactory != null) { PipeFactory.Close(); } RemotingObject = null; PipeFactory = null; }
private static int ClientMain(string[] args) { var configFilename = Path.Combine(Path.GetDirectoryName(typeof(ClientService).Assembly.Location) ?? throw new InvalidOperationException(), "client.config"); RemotingConfiguration.Configure(configFilename, false); var remotingObject = new RemotingObject(); Console.WriteLine($"Remoting object text = {remotingObject.Text}"); var remotingObject2 = remotingObject.OtherRemotingObject; Console.WriteLine($"Remoting object 2 text = {remotingObject2.Text}"); if (!(remotingObject2 is MarshalByRefObject objectToSponsor)) { throw new InvalidOperationException("Object is not MarshalByRefObject"); } var sponsor = new ClientSideSponsor(objectToSponsor); sponsor.Register(new TimeSpan(0, 0, 0, 0, 200)); // Register with lifetime of 2 seconds // Wait a while. Sponsor should get a renewal in this time. WaitHandle.WaitAny(new WaitHandle[] { StopEvent }, new TimeSpan(0, 0, 20)); return(0); }
public void Main() { var remoting = new RemotingObject(); }