Title: Bi-directional remoting

How would you create such a bi-directional channel?  All the samples I used so far are only server-client, but not the other way around.

I have a delegate that I want to implement on the client side.  The class implementing the callback sits on the client (of course).

I even use the common abstract pattern described by a Microsoft KB article, but still no luck.

Debug output:

ASP.Net Server starting

Server.Do start

An unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll

Additional information: This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.


Here is the sample code:


CommonLib: [both server and client have access]

-----------------------------------------------

using System;

using System.Runtime.Remoting;

public delegate void BaseEventHandler(object sender,RemoteEventArgs e);

[Serializable]

public class RemoteEventArgs : EventArgs

{

        public static new RemoteEventArgs Empty = new RemoteEventArgs();

}

public abstract class RemoteCallback : MarshalByRefObject

{

        [System.Runtime.Remoting.Messaging.OneWay]

        public void Callback(object sender,RemoteEventArgs e)

        {

                CallbackImpl(sender,e);

        }

        protected abstract void CallbackImpl(object sender,RemoteEventArgs e);

}

public interface IServer

{

        event BaseEventHandler Evt;

        void Do();

}


ASP.Net Server:

--------------------------------------------

class S : MarshalByRefObject, IServer

{

        public event BaseEventHandler Evt;

        public void Do()

        {

                System.Diagnostics.Debug.WriteLine("Server.Do start");

                if (Evt != null) Evt(this,RemoteEventArgs.Empty);

                System.Diagnostics.Debug.WriteLine("Server.Do end");

        }

}

public class Service1 : System.Web.Services.WebService

{

        ... // standard web service stuff (autogenerated)

        static bool Init = false;

        [WebMethod]

        public void StartUp()

        {

                if (!Init)

                {

                        RemotingConfiguration.Configure("/Server.config");

                        Init = true;

                }

                System.Diagnostics.Debug.WriteLine("ASP.Net Server starting");

        }

}

<configuration>

  <system.runtime.remoting>

    <application>

      <service>

        <wellknown

           mode="Singleton"

           type="S, Server"

           objectUri="S"

        />

      </service>

      <channels>

        <channel ref="tcp" port="8085">

          <serverProviders>

                <formatter ref="binary"/>

          </serverProviders>

        </channel>

      </channels>

    </application>

  </system.runtime.remoting>

</configuration>

Client:

--------------------------------------------

using System;

using System.Runtime.Remoting;

public class Test

{

        static void Main()

        {

                RemotingConfiguration.Configure("../../Client.config");

               

                new Client.localhost.Service1().StartUp();

                IServer s = Activator.GetObject(typeof(IServer),"tcp://localhost:8085/S") as IServer;

                s.Evt += new BaseEventHandler(

                        new ClientChangedCallback().Callback);

                s.Do();

                System.Diagnostics.Debug.WriteLine("I never get here");

        }

}

public class ClientChangedCallback : RemoteCallback

{

        protected override void CallbackImpl(object sender,RemoteEventArgs e)

        {

                System.Diagnostics.Debug.WriteLine("And of course I never get here");

        }

}

<configuration>

  <system.runtime.remoting>

     <application>

        <channels>

           <channel ref="tcp">

              <clientProviders>

                 <formatter ref="binary"/>

              </clientProviders>

           </channel>

        </channels>

     </application>

  </system.runtime.remoting>

</configuration>

Reply via email to