连接在一起是如此的简单。以下的服务器应用提供了一个服务,可将一个字符串的字母顺序反转。
Server.cs using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.HTTP;
namespace RemotingSample
{
public class Reverser : MarshalByRefObject
{
public string Reverse(string text)
{
Console.WriteLine("Reverse({0})", text);
string rev = "";
for (int i=text.Length-1; i>=0; i--)
{
rev += text[i];
}
Console.WriteLine("returning : {0}", rev);
return rev;
}
}
public class TheApp
{
public static void Main()
{
file:// Create a new HTTP channel that
// listens on port 8000
HTTPChannel channel = new HTTPChannel(8000);
// Register the channel with the runtime
ChannelServices.RegisterChannel(channel);
// Expose the Reverser object from this server
RemotingServices.RegisterWellKnownType(
"server", // assembly name
"RemotingSample.Reverser", // full type name
"Reverser.soap", file:// URI
WellKnownObjectMode.Singleton // instancing mode
);
// keep the server running until
// the user presses enter
Console.WriteLine("Server.exe");
Console.WriteLine("Press enter
| 对此文章发表了评论 |

