我爱Aspx >> Asp.Net >> Microsoft .NET Remoting:技术概述(二)Console.ReadLine();
}
}
}
现在我们已经拥有了一个字符反向服务,以下我们将建立一个客户应用来使用这个服务:
Client.cs using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.HTTP;
using RemotingSample; // reference the server
public class TheApp
{
public static void Main()
{
// Create and register a channel
// to comunicate to the server.
// The client will use port 8001
// to listen for callbacks
HTTPChannel channel = new HTTPChannel(8001);
ChannelServices.RegisterChannel(channel);
// create an instance on the remote server
// and call a method remotely
Reverser rev = (Reverser)Activator.GetObject(
typeof(Reverser), // type to create
"http://localhost:8000/Reverser.soap" file:// URI
);
Console.WriteLine("Client.exe");
Console.WriteLine(rev.Reverse("Hello, World!"));
}
}
************图一 图二*******************
看,通过远程.net将两个应用连接在一起是多么的简单。当服务端和客户端程序放在两台不同的机器时,我们可以令两个程序都运行在80端口。这样远程的调用就可通过一个防火墙。你也可将HTTPChannel改为一个TCPChannel试一下。
你要注意到,客户端是通过“Reverser.soap”来标识它想连接的对象的。这个名字与服务器代码中RegisterWellKnownType的URI参数符合。“.soap”的扩展是不必要的。URI可以是任何的字符串,只要它能唯一标识服务器的对象就可以了。“.soap”的扩展只是用来提醒我们HTTP channel是使用soap来格式化信息的。
在上面有关channel的例子中,你可能会产生这样的疑问:参数是如何跨网络传送,返回值又是如何送回的呢?答案是,在参数被跨网络传送之前,他们必须经过串行化处理。对于需要传送的所有对象或者结构,都要经过这样的处理。串行化的处理很简单,只是以连续字节的方式建立变量或者对象中的数据的一个持续拷贝。将这些字节还原为一个值或者对象实例的处理被称为反串行化。
Ҷƪл˵?
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]
运用VB.net创建Web服务访问程序[05-15]
ASP.NET服务器端异步Web方法[05-15]
Remoting事件机制续[05-15]
Remoting和Web服务的区别[05-15]
Microsoft .Net Remoting系列专题..[05-15]
如何解决Remoting无法传输存储过..[05-15]
.NET Framework中的串行化操作[05-15]
.Net Remoting与Server 对象详解[05-15]
解析.Net框架下的序列化机制[05-15]
微软 .NET Remoting体系结构评估[05-15]
remoting使用手记[05-15]
[Remoting]当client不复存在而Re..[05-15]