我爱Aspx >> Asp.Net >> Microsoft .Net Remoting系列专题之三:Remoting事件处理全接触if (txtInfo.Text != string.Empty)
{
ServerForm.Obj.BroadCastingInfo(txtInfo.Text);
}
else
{
MessageBox.Show("请输入信息!");
}
但是很简单,就是调用远程对象的发送消息方法而已。
现在该实现客户端了。我们可以参照前面的例子,只是把服务端改为客户端而已。另外考虑到序列化安全级别的问题,所以代码会是这样:
private void ClientForm_Load(object sender, System.EventArgs e)
{
BinaryServerFormatterSinkProvider serverProvider = new
BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clientProvider = new
BinaryClientFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
HttpChannel channel = new HttpChannel(props,clientProvider,serverProvider);
ChannelServices.RegisterChannel(channel);
watch = (IBroadCast)Activator.GetObject(
typeof(IBroadCast),"http://localhost:8080/BroadCastMessage.soap");
watch.BroadCastEvent += new BroadCastEventHandler(BroadCastingMessage);
}
注意客户端通道的端口号应设置为0,这表示客户端自动选择可用的端口号。如果要设置为指定的端口号,则必须保证与服务端通道的端口号不相同。
然后是,BroadCastEventHandler委托的方法:
public void BroadCastingMessage(string message)
{
txtMessage.Text += "I got it:" + message;
txtMessage.Text += System.Environment.NewLine;
}
客户端界面如图:

Microsoft .Net Remoting系列专题..[05-15]
Microsoft .NET Remoting:技术概..[05-15]
Microsoft .Net Remoting系列专题..[05-15]
.NET Framework中的串行化操作[05-15]
.Net Remoting与Server 对象详解[05-15]
解析.Net框架下的序列化机制[05-15]
微软 .NET Remoting体系结构评估[05-15]
ASP.NET创建Web服务之使用事务[05-15]
ASP.NET创建Web服务之发布和部署[05-15]
HTTP 安全性和 ASP.NET Web 服务[05-15]
Microsoft .Net Remoting系列专题..[05-15]
一步一步学Remoting之四:承载方..[05-15]
一步一步学Remoting之一:从简单..[05-15]
一步一步学Remoting之五:异步操..[05-15]
Microsoft .NET Remoting:技术概..[05-15]
Remoting事件机制续[05-15]
Remoting和Web服务的区别[05-15]
Microsoft .Net Remoting系列专题..[05-15]
如何解决Remoting无法传输存储过..[05-15]
.NET Framework中的串行化操作[05-15]