[在线等]remoting中一个奇怪的问题,到底能否一个EXE文件还是一个DLL文件。分不够我再开贴
代码如下
我在编译好服务器端之后,生成一个文件RemotingSample.exe.
然后编译客户端,这时候提示说“未引入程序集RemotingSample”
于是我 using RemotingSample; // reference the server 之后就在.net IDE环境下的资源管理器的引用中添加文件。但提示无法添加RemotingSample。。。。
提示说不是DLL或者COM组件
我想可能是我经验差,搞错了,就差MSDN文档,例子虽然名字变了,但原理还是一样的。。。。。。。。。。
我想我是那里搞错了,既然这能作为例子师范,应该没有错吧??
可参考:http://expert.csdn.net/Expert/topic/2930/2930567.xml?temp=.7674066
----------------------------------------------------------------
在这个例子中,我们将可以看到使用HTTP channel把两个应用
连接在一起是如此的简单。以下的服务器应用提供了一个服务,可将一个字符串的字母顺序反转。
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 to stop server...");
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!"));
}
}