我看了几个Remoting的范例,自己做总是做不成功,有个问题一直想不明白,
假设有个dll我想把他做成远程访问的组件 ,但是当我客户端调用该组件的时候,在实例化时总是说我没有申明,在编译客户端的时候还要加入该组件才行,那我怎么知道我客户端运行时到底调用了服务器端的远程组件没有啊,望高手指点迷津远程组件:remote.dll
客户端:
 Dim channel As New HttpChannel(0)
      ChannelServices.RegisterChannel(channel)      ' Registers the remote class. (This could be done with a
      ' configuration file instead of a direct call.)
      RemotingConfiguration.RegisterWellKnownClientType(Type.GetType("ServiceClass, remote"), "http://localhost:8080/object1uri")      ' Instead of creating a new object, this obtains a reference
      ' to the server's single instance of the ServiceClass object.
      Dim object1 As ServiceClass = New ServiceClass()      Try
         Console.WriteLine("ServerTime: " & object1.GetServerTime())
      Catch ex As Exception
         Console.WriteLine("Exception of type: " & ex.GetType.ToString & " occurred.")
         Console.WriteLine("Details: " & ex.Message)
      End Try
这是微软的一个例子:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconremotingexamples.asp就是当客户端实例化这个Dim object1 As ServiceClass = New ServiceClass()
的时候,会出现没有申明,要引用remote.dll,难道编译客户端的时候一定要引用远程的dll吗,

解决方案 »

  1.   

    一定要,不然它怎么知道调用哪个,你可以再做一个接口,在客户端引用接口就可以了,不用把整个服务器端的DLL引用
      

  2.   

    有没有好的范例,发个给我啊:   [email protected]
      

  3.   

    我这里也有个问题,请高手给于解决:
    假设我要远程访问的组件要实现事务控制,那么我可以让这个组件从servicecomponent继承,在COM+环境中运行,而我们又知道要是实现引用传递的远程组件,必须从MarshalByRefObject
    继承,那么我怎样能做到访问远程机器上的COM+组件呢?
      

  4.   

    TO:ytwxw(wxw)    两个都继承不行吗?好象可以吧,在webservice里面,他本来就支持事务的,因为webservice本身就是继承于servicecomponent ,而在Remoting 里面我没有尝试过,你可以试试,继承于他们两个
      

  5.   

    server:
    using System;
    using System.Runtime.Remoting.Channels; //To support and handle Channel and channel sinks
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels.Http; //For HTTP channel
    using System.IO;namespace ServerApp
    { public class RemotingServer
    {
    public RemotingServer()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    }
    //Service class
    public class Service: MarshalByRefObject 
    {
    public void WriteMessage (int num1,int num2) 
    {
    SyncLock Me;
    Console.WriteLine (Math.Max(num1,num2));
    End SyncLock;
    }
    }
    //Server Class
    public class Server
    {
    public static void Main () 
    {
    HttpChannel channel = new HttpChannel(8001); //Create a new channel
    ChannelServices.RegisterChannel (channel); //Register channel
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Service),"Service",WellKnownObjectMode.Singleton); 
    Console.WriteLine ("Server ON at port number:8001");
    Console.WriteLine ("Please press enter to stop the server.");
    Console.ReadLine ();
    }
    }}
    //说明:先建好服务器端,再用命令:
    //soapsuds -url:http://< Machine Name where service is running>:8001/Service?WSDL -oa:Server.dll
    //生成客户端引用的DLL
    //建立客户端,即可
    client
    using System;
    using System.Runtime.Remoting.Channels; //To support and handle Channel and channel sinks
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels.Http; //For HTTP channel
    using System.IO;
    using ServerApp;
    namespace RemotingApp
    { public class ClientApp
    {
    public ClientApp()
    { } public static void Main (string[] args) 
    {
    HttpChannel channel = new HttpChannel (8002); //Create a new channel
    ChannelServices.RegisterChannel (channel); //Register the channel
    //Create Service class object
    Service svc = (Service) Activator.GetObject (typeof (Service),"http://cap36:8001/Service"); //Localhost can be replaced by 
    //Pass Message
    svc.WriteMessage (10,20); 
    } }
    }