I'm trying to get an asynch remoting call to work and I think I'm missing
something simple. I have two console apps: 1 client and the other hosting
the server object. When I try to do the BeginInvoke:

IAsyncResult ar = d.BeginInvoke(cb, null);

I get a runtime error "Cannot load type soap:ServiceClass" followed by some
cryptic text. Do I need to use TCP for this, or can I use HTTP? Also, the
reference for the client code was made using the soapsuds.exe utility. Any
thoughts?

Thanks,

Sean

PS> I included the code below in case someone is up to check it out...


/////////////////////////////////////////////
///Server Code
/////////////////////////////////////////////
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

namespace Server 
{
        public class ServiceClass : MarshalByRefObject 
        {
                public string AddMessage (String msg) 
                {
                        Console.WriteLine (msg);
                        return "Message written...";
                }

                public string TimeConsumingRemoteCall()
                {
                        Console.WriteLine("TimeConsumingRemoteCall
called.");
   
                        for(int i = 0; i < 20000; i++)
                        {
                                Console.Write("Counting: " + i.ToString());
                                Console.Write("\r");
                        }
                        return "This is a time-consuming call.";
                }
        }

        public class ServerClass 
        {
                public static void Main () 
                {
                        HttpChannel c = new HttpChannel (1095);
                        ChannelServices.RegisterChannel(c);
        
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServiceClass),"Ser
viceClass",WellKnownObjectMode.Singleton);    
                        Console.WriteLine ("Server ON at 1095");
                        Console.WriteLine ("Press enter to stop the
server...");
                        Console.ReadLine ();
                }
        }
}


/////////////////////////////////////////////
///Client Code
/////////////////////////////////////////////
using System;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Channels.Http;
using Server;

public class TheClient 
{
        public delegate string MyDelegate();
        public static ManualResetEvent e;

        [OneWayAttribute]
        public static void MyCallBack(IAsyncResult ar) 
        {
                MyDelegate d = (MyDelegate)((AsyncResult)ar).AsyncDelegate;
                Console.WriteLine(d.EndInvoke(ar));
                e.Set();
        }

        public static void Main(string[] Args)
        {
                TheClient HandlerInstance = new TheClient();
                HandlerInstance.Run();         
        }

        public void Run()
        { 
                e = new ManualResetEvent(false);

                HttpChannel c = new HttpChannel(1077);  
                ChannelServices.RegisterChannel(c);
                ServiceClass sc = (ServiceClass) Activator.GetObject (typeof
(ServiceClass),"http://localhost:1095/ServiceClass";); 
                string s = sc.AddMessage ("Hello From Client");
                Console.WriteLine("return value: {0}", s);

                AsyncCallback cb = new AsyncCallback(TheClient.MyCallBack);
                MyDelegate d = new MyDelegate(sc.TimeConsumingRemoteCall);
                try
                {
                        //chokes here
                        IAsyncResult ar = d.BeginInvoke(cb, null);
                }
                catch(Exception ex)
                {
                        Console.WriteLine(ex.Message + "\r\r" +
ex.StackTrace);
                }
                e.WaitOne();
                Console.WriteLine("Press ENTER to continue...");
                Console.ReadLine();
        }
}

Reply via email to