但我有个问题就是,我注册的远程对象是dll中的类,那这个dll要拷贝到client端的机器吗?
是<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode = "Singleton" type = "classlib.SayHello,classlib" objectUri = "Server1" />
<wellknown mode = "SingleCall" type = "classlib.SayHello,classlib" objectUri = "Server2" />
</service>
<channels>
<channel ref="http" name="MyChannel" port = "9000" />
</channels>
</application>
<debug loadTypes="true" />
</system.runtime.remoting>
</configuration>建议用TCP channel,否则和webservice没有什么区别
是<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode = "Singleton" type = "classlib.SayHello,classlib" objectUri = "Server1" />
<wellknown mode = "SingleCall" type = "classlib.SayHello,classlib" objectUri = "Server2" />
</service>
<channels>
<channel ref="http" name="MyChannel" port = "9000" />
</channels>
</application>
<debug loadTypes="true" />
</system.runtime.remoting>
</configuration>建议用TCP channel,否则和webservice没有什么区别
服务器端代码
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace ServerSayHello
{
public class ServerSayHello
{
public static void Main()
{
RemotingConfiguration.Configure("../../Remoting.cfg");
Console.WriteLine("按 <enter> 退出...");
Console.ReadLine();
}
}
}客户端配置文件
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown url="http://localhost:9000/Server2"
type = "classlib.SayHello,classlib"
/>
</client>
</application>
<debug loadTypes="true" />
</system.runtime.remoting>
</configuration>
客户端代码
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Reflection ;
using System.Runtime.Remoting.Activation;
using classlib;
namespace RemotingSamples
{
public class Client
{
public static void Main()
{
RemotingConfiguration.Configure("../../client.exe.config");
SayHello obj=new SayHello();
Console.WriteLine("Obj.Client={0}",obj.Hello("dd"));
}
}
}
<wellknown mode = "SingleCall" type = "classlib.SayHello,classlib" objectUri = "Server2" />中,objectUri = "Server1"如何理解,谢谢。另外,客户端不需要拷贝任何文件,只需要进行配置就可以了吗?显然server端注册的是命名空间classlib 下的sayhello类,但是这个命名空间写在哪,是写在一个dll中,然后拷贝到客户端,让客户端引用吗?
type = "classlib.SayHello,classlib"
就是SingleCall调用第二个名称为Server2的对象
是
好像不行啊,我每次还是要拷贝执行数据库操作的dll到客户端机器,怎么解决这个问题啊,是必须要这样做吗?
是,你要知道是客户端让服务器做事情,而不是在客户端本地做事情RemotingConfiguration.Configure("../../client.exe.config");
SayHello obj=new SayHello();
第一句用了就是调用服务器端对象,不用就是调用本地对象客户端如果是web的,那配置文件怎么写呢,是不是要写在web.config中啊
随便给个名字就可以了