static void Main(string[] args) { try { //// 使用tcp建立通道,port為8050 var tcpChannel = new System.Runtime.Remoting.Channels.Tcp.TcpChannel(8050); //// 註冊剛剛建立的tcp channel,這邊使用簡單的範例所以將ensureSecurity設為false System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(tcpChannel, false); //// 使用http建立通道,port為8051 System.Runtime.Remoting.Channels.Http.HttpChannel httpChannecl = new System.Runtime.Remoting.Channels.Http.HttpChannel(8051); //// 註冊剛剛建立的http channel,這邊使用簡單的範例所以將ensureSecurity設為false System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(httpChannecl, false); //// 註冊 Remoting 服務的物件與物件啟動的方式(SingleCall) //// WellKnownObjectMode有兩種 //// Singleton 每個內送訊息都是由新的物件執行個體 (Instance) 服務。 //// SingleCall 每個內送訊息都是由同一個物件執行個體服務。 System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType( typeof(InterfaceOfWork), "RemotingTest", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
public void FixtureSetup() { if (!serverStarted) //should always evaluate to true { httpChannel = new System.Runtime.Remoting.Channels.Http.HttpChannel(0); StartServer(); } }
public override void SetUp() { base.SetUp(); Random rnd = new Random((int) (DateTime.Now.Ticks & 0x7fffffff)); port = rnd.Next(System.Net.IPEndPoint.MinPort, System.Net.IPEndPoint.MaxPort); httpChannel = new System.Runtime.Remoting.Channels.Http.HttpChannel(port); if (!serverStarted) StartServer(); }
public void FixtureTeardown() { try { System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(httpChannel); } catch { } httpChannel = null; }
public override void TearDown() { try { System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(httpChannel); } catch { } httpChannel = null; base.TearDown(); }
public FormMain() { InitializeComponent(); int port = Settings.Default.Port; toolStripTextBoxPort.Text = port.ToString(); try { System.Runtime.Remoting.Channels.Http.HttpChannel channel = new System.Runtime.Remoting.Channels.Http.HttpChannel(port); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(LoaderObject) , "LoaderObject.rem", System.Runtime.Remoting.WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType(typeof(ListenerService) , "Srvtools.rem", System.Runtime.Remoting.WellKnownObjectMode.Singleton); try { ShowForm("WCFServer", "WCFServer.FormListerner"); } catch { } } catch(Exception e) { MessageBox.Show(e.Message); } //Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //IPEndPoint ip = new IPEndPoint(IPAddress.Any, Config.ServerLoaderPort); //try //{ // server.Bind(ip); // server.Listen(10); // server.BeginAccept(new AsyncCallback(Connect), server); //} //catch (SocketException es)//端口被占用 //{ // if (es.ErrorCode == 10048) // { // MessageBox.Show("Port of ServerLoader is being used now\r\nPlease change the port in the options"); // } //} }
private void btn_start_Click(object sender, EventArgs e) { if (bApiServerIsRunning) { //停止; EohiDataRemoteObject.ApiHelper.ApiRequsetSendedEvent -= ApiHelper_ApiRequsetSendedEvent; bApiServerIsRunning = false; } else { GetList(); int iport = 9933; string port = Common.Util.LocalConfigXml.GetKey("remoting.xml", "remotingport", false); try { iport = Convert.ToInt32(port); } catch (Exception) { } //启用remoting服务; System.Runtime.Remoting.Channels.Http.HttpChannel channel = new System.Runtime.Remoting.Channels.Http.HttpChannel(iport); ChannelServices.RegisterChannel(channel, false); //启动; this.label_apiitemcount.Text = this.apiItemList.Count.ToString(); //注册响应方法; RemotingConfiguration.RegisterWellKnownServiceType(typeof(EohiDataRemoteObject.ApiHelper), "apihelper", WellKnownObjectMode.SingleCall); EohiDataRemoteObject.ApiHelper.ApiRequsetSendedEvent += ApiHelper_ApiRequsetSendedEvent; // bApiServerIsRunning = true; } SetStartButton(); }
private System.Runtime.Remoting.Channels.Http.HttpChannel GetHttpChannel() { Random rnd = new Random((int) (DateTime.Now.Ticks & 0x7fffffff)); port = rnd.Next(System.Net.IPEndPoint.MinPort, System.Net.IPEndPoint.MaxPort); System.Runtime.Remoting.Channels.Http.HttpChannel ch = new System.Runtime.Remoting.Channels.Http.HttpChannel(port); return ch; }