Inheritance: System.MarshalByRefObject
        }     //ClientInvoke

        /// <summary>
        /// Used by AsyncClient.Run() to invoke the proxy method repeatedly.
        /// </summary>
        /// <param name="obj"></param>
        public void ClientInvokeAsync(object RemoteObj)
        {
            try
            {
                if (RemoteObj == null)
                {
                    Console.WriteLine("Could not locate server.");
                    return;
                }//if

                switch (m_CallConv)
                {
                case CallingConvention.ByRef:
                {
                    AsyncCallback    cb   = new AsyncCallback(ByRefCallBack);
                    HelloServerByRef hsbr = (HelloServerByRef)RemoteObj;
                    ByRefDelegate    del  = new ByRefDelegate(hsbr.HelloMethod);
                    ForwardByRef     fbr  = new ForwardByRef();
                    IAsyncResult     ar   = del.BeginInvoke("Calling ByRef async", fbr, cb, null);
                    lock (this)
                    {
                        m_ResetEvent = new ManualResetEvent(false);
                    }//lock
                    m_ResetEvent.WaitOne();
                    if (m_ThreadNumber > 0)
                    {
                        Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                    } //if
                    break;
                }     //case

                case CallingConvention.ByVal:
                {
                    AsyncCallback    cb   = new AsyncCallback(ByValCallBack);
                    HelloServerByVal hsbv = (HelloServerByVal)RemoteObj;
                    ByValDelegate    del  = new ByValDelegate(hsbv.HelloMethod);
                    ForwardByVal     fbv  = new ForwardByVal();
                    IAsyncResult     ar   = del.BeginInvoke("Calling ByVal async", fbv, cb, null);
                    lock (this)
                    {
                        m_ResetEvent = new ManualResetEvent(false);
                    }//lock
                    m_ResetEvent.WaitOne();
                    if (m_ThreadNumber > 0)
                    {
                        Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                    } //if
                    break;
                }     //case
                }     //switch
            }         //try
            catch (Exception e)
            {
                Console.WriteLine("Exception in Client.ClientInvokeAsync(): {0}", e.ToString());
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            } //catch
            return;
        }     //ClientInvokeAsync()
        }     //Run()

        /// <summary>
        /// Sequential invocation method.
        /// </summary>
        /// <param name="RemoteObj"></param>
        public void ClientInvoke(object RemoteObj)
        //public void ClientInvoke()
        {
            try
            {
                if (RemoteObj == null)
                {
                    Console.WriteLine("Could not locate server.");
                    return;
                }//if

                lock (this)
                {
                    switch (m_CallConv)
                    {
                    case CallingConvention.ByRef:
                    {
                        HelloServerByRef hsbr = (HelloServerByRef)RemoteObj;
                        ForwardByRef     fbr  = new ForwardByRef();
                        string           str  = hsbr.HelloMethod("Calling ByRef sequential", fbr);
                        Console.WriteLine("Output from HelloMethod(): {0}", str);

                        if (m_ThreadNumber > 0)
                        {
                            Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                        }//if
                        break;
                    }

                    case CallingConvention.ByVal:
                    {
                        HelloServerByVal hsbv      = (HelloServerByVal)RemoteObj;
                        ForwardByVal     fbv       = new ForwardByVal();
                        ForwardByVal     returnfbv = hsbv.HelloMethod("Calling ByVal sequential", fbv);
                        Console.WriteLine("Output from forwarded object: {0}", returnfbv.Message);
                        if (m_ThreadNumber > 0)
                        {
                            Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                        }//if
                        break;
                    }

                    default:
                        throw new System.InvalidOperationException("Invalid calling convention in Run()");
                    } //switch
                }     //end lock(this)
            }         //try
            catch (Exception e)
            {
                Console.WriteLine("Exception in Client.ClientInvoke(): {0}", e.ToString());
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            } //catch
            return;
        }     //ClientInvoke
Beispiel #3
0
        }//constructor

        public string HelloMethod(string text, ForwardByRef fbr)
        {
            lock (this)
            {
                m_CallCount++;

                fbr.CallMe("Regards from the server");
                Console.WriteLine("\nHello.HelloMethod : {0}", text);
                Console.WriteLine("Number of calls on this instance: {0}\n", m_CallCount);
                return("Hi there " + text);
            } //lock
        }     //HelloMethod()
    }//constructor

    public string HelloMethod(string text, ForwardByRef fbr)
    {
      lock(this)
      {
        m_CallCount++;

        fbr.CallMe("Regards from the server");
        Console.WriteLine("\nHello.HelloMethod : {0}", text);
        Console.WriteLine("Number of calls on this instance: {0}\n", m_CallCount);
        return "Hi there " + text;
      }//lock
    }//HelloMethod()
Beispiel #5
0
    }//ClientInvoke

    /// <summary>
    /// Used by AsyncClient.Run() to invoke the proxy method repeatedly.
    /// </summary>
    /// <param name="obj"></param>
    public void ClientInvokeAsync(object RemoteObj)
    {
      try
      {
        if (RemoteObj == null)
        {
          Console.WriteLine("Could not locate server.");
          return;
        }//if

        switch (m_CallConv)
        {
          case CallingConvention.ByRef:
          {
            AsyncCallback cb = new AsyncCallback(ByRefCallBack);
            HelloServerByRef hsbr = (HelloServerByRef)RemoteObj;
            ByRefDelegate del = new ByRefDelegate(hsbr.HelloMethod);
            ForwardByRef fbr = new ForwardByRef();
            IAsyncResult ar = del.BeginInvoke("Calling ByRef async", fbr, cb, null);
            lock(this)
            {      
              m_ResetEvent = new ManualResetEvent(false);
            }//lock
            m_ResetEvent.WaitOne();
            if (m_ThreadNumber > 0)
            {
              Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
            }//if
            break;
          }//case
          case CallingConvention.ByVal:
          {
            AsyncCallback cb = new AsyncCallback(ByValCallBack);
            HelloServerByVal hsbv = (HelloServerByVal)RemoteObj;
            ByValDelegate del = new ByValDelegate(hsbv.HelloMethod);
            ForwardByVal fbv = new ForwardByVal();
            IAsyncResult ar = del.BeginInvoke("Calling ByVal async", fbv, cb, null);
            lock(this)
            {      
              m_ResetEvent = new ManualResetEvent(false);
            }//lock
            m_ResetEvent.WaitOne();
            if (m_ThreadNumber > 0)
            {
              Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
            }//if
            break;
          }//case
        }//switch
      }//try
      catch (Exception e)
      {
        Console.WriteLine("Exception in Client.ClientInvokeAsync(): {0}", e.ToString());
        System.Diagnostics.Process.GetCurrentProcess().Kill();
      }//catch
      return;
    }//ClientInvokeAsync()
Beispiel #6
0
    }//Run()

    /// <summary>
    /// Sequential invocation method.  
    /// </summary>
    /// <param name="RemoteObj"></param>
    public void ClientInvoke(object RemoteObj)
    //public void ClientInvoke()
    {
      try
      {
        if (RemoteObj == null)
        {
          Console.WriteLine("Could not locate server.");
          return;
        }//if

        lock (this)
        {
          switch (m_CallConv)
          {
            case CallingConvention.ByRef:
            {
              HelloServerByRef hsbr = (HelloServerByRef) RemoteObj;
              ForwardByRef fbr = new ForwardByRef();
              string str = hsbr.HelloMethod("Calling ByRef sequential", fbr);
              Console.WriteLine("Output from HelloMethod(): {0}", str);

              if (m_ThreadNumber > 0)
              {
                Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
              }//if
              break;
            }
            case CallingConvention.ByVal:
            {
              HelloServerByVal hsbv = (HelloServerByVal) RemoteObj;
              ForwardByVal fbv = new ForwardByVal();
              ForwardByVal returnfbv = hsbv.HelloMethod("Calling ByVal sequential", fbv);
              Console.WriteLine("Output from forwarded object: {0}", returnfbv.Message);
              if (m_ThreadNumber > 0)
              {
                Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
              }//if
              break;
            }
            default:
              throw new System.InvalidOperationException("Invalid calling convention in Run()");
          }//switch
        }//end lock(this)
      }//try
      catch (Exception e)
      {
        Console.WriteLine("Exception in Client.ClientInvoke(): {0}", e.ToString());
        System.Diagnostics.Process.GetCurrentProcess().Kill();
      }//catch
      finally
      {
        //Unregister the channels so app can execute again.
        if (m_HttpChannel != null)
        {
          ChannelServices.UnregisterChannel(m_HttpChannel);
        }//if

        if (m_TcpChannel != null)
        {
          ChannelServices.UnregisterChannel(m_TcpChannel);
        }//if

      }//finally
      return;

    }//ClientInvoke