客户端与服务端通信? 客户端发出读文件请求,服务端响应,并将服务端文件内容显示在客户端c#.net中Remoting实现新手,谁有具体时间代码?多谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一言难尽,仅供参考server://注册提供服务的远程对象 this.Exporter.Export("Register WellKnown Service(Singlecall)..."); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Processor), RemotingService.Remoting_Service_Value, WellKnownObjectMode.SingleCall); this.Exporter.ExportLine("OK"); this.Exporter.ExportLine("WellKnown Service = " + RemotingService.Remoting_Service_Value + ", type=" + typeof(Processor) + ", Port=" + RemotingService.Remoting_Port_Value);client: //异步调用 this._process = (IProcess)Activator.GetObject(typeof(IProcess), this._url); AsyncMethodCallerA caller = new AsyncMethodCallerA(this._process.ProcessObj); IAsyncResult result = caller.BeginInvoke(requireObj, null, null); while (result.IsCompleted == false) { Thread.Sleep(50); System.Windows.Forms.Application.DoEvents(); } object responseObj = caller.EndInvoke(result //服务接口public interface IProcessor{ object RemoteExecute(object serializableObj);//应用方法}//服务实现public class Processor : IProcessor{ public object RemoteExecute(object serializableObj) { //读文件->文件数据->返回文件数据 string[] fileData = System.IO.File.ReadAllLines("test.txt"); return fileData; }}//服务端//开始服务IChannel channel = new TcpChannel(7001);ChannelServices.RegisterChannel(channel, false);//注册一个TCP通道RemotingConfiguration.RegisterWellKnownServiceType(typeof(Processor), "myService", WellKnownObjectMode.SingleCall);//注册服务对象//停止服务,注意关闭TcpChannel通道public void ReleaseChannel(){ foreach (IChannel channel in channels){ if (channel is TcpChannel){ TcpChannel tcpChannel = (TcpChannel)channel; tcpChannel.StopListening(null);//关闭监听 } }//客户端string url = "tcp://localhost:7001/myService";//远程服务URLIProcess process = (IProcess)Activator.GetObject(typeof(IProcess), url);//取得远程访问代理对象object fileData = process.RemoteExecute(null);//远程调用 RollingPointPairList list 急救!!请高手指点 获取子窗体问题 如何在WIN FORM或命令控制台程序中查看一个文件的类型 怎么在ContentMenu一个菜单项前加说明文字? 一段简单的代码出错了,请各位大侠指点一下! dotnet2005序列化怎么少了soap序列化方式 怎么样编写一个小程序可以自动通过串口接收话单,并截取出相应有用部分 javascript 调用后台代码问题 .net java 好书推荐 combobox的未将对象的引用设置到对象的实例错误 C#如何取得字符串地址
//注册提供服务的远程对象
this.Exporter.Export("Register WellKnown Service(Singlecall)...");
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Processor), RemotingService.Remoting_Service_Value, WellKnownObjectMode.SingleCall);
this.Exporter.ExportLine("OK");
this.Exporter.ExportLine("WellKnown Service = " + RemotingService.Remoting_Service_Value
+ ", type=" + typeof(Processor) + ", Port=" + RemotingService.Remoting_Port_Value);client:
//异步调用
this._process = (IProcess)Activator.GetObject(typeof(IProcess), this._url);
AsyncMethodCallerA caller = new AsyncMethodCallerA(this._process.ProcessObj);
IAsyncResult result = caller.BeginInvoke(requireObj, null, null);
while (result.IsCompleted == false) {
Thread.Sleep(50);
System.Windows.Forms.Application.DoEvents();
}
object responseObj = caller.EndInvoke(result
public interface IProcessor
{
object RemoteExecute(object serializableObj);//应用方法
}//服务实现
public class Processor : IProcessor
{
public object RemoteExecute(object serializableObj)
{
//读文件->文件数据->返回文件数据
string[] fileData = System.IO.File.ReadAllLines("test.txt");
return fileData;
}
}//服务端
//开始服务
IChannel channel = new TcpChannel(7001);
ChannelServices.RegisterChannel(channel, false);//注册一个TCP通道
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Processor), "myService", WellKnownObjectMode.SingleCall);//注册服务对象//停止服务,注意关闭TcpChannel通道
public void ReleaseChannel()
{
foreach (IChannel channel in channels){
if (channel is TcpChannel){
TcpChannel tcpChannel = (TcpChannel)channel;
tcpChannel.StopListening(null);//关闭监听
}
}//客户端
string url = "tcp://localhost:7001/myService";//远程服务URL
IProcess process = (IProcess)Activator.GetObject(typeof(IProcess), url);//取得远程访问代理对象
object fileData = process.RemoteExecute(null);//远程调用