?
Solved

Vb.net remoting with interface

Posted on 2006-06-25
5
Medium Priority
?
355 Views
Last Modified: 2010-04-23
Hi, i am having alot of problems with remoting in .net. What i am trying to achieve here is to, build a interface class so the client side will reference to it and call the methods from the server side. Can this be done without compiling the source to dll? I guess i am abit lost with the many different ways of using remoting in .net. I would appreciate if someone could write me a small sample remoting app which consists of a IhelloWorld interface, hellowWorldCls the host and client to use the 2. I have searched the web, most samples dont work or they are either to complex for beginner's understanding. The simplest sample i found was at

http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/Remoting/firstserver.aspx

but it appears that it won't run correctly, a null value execptions would appear. Would anyone take a look at the sample and post what are the modifications needed to run the app.

Your help would be very much appreciated.

thank you.
0
Comment
Question by:jaxrpc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 1000 total points
ID: 16981728
0
 
LVL 5

Assisted Solution

by:t_itanium
t_itanium earned 1000 total points
ID: 16983314
i will give you the code in c#..try to convert it else tell me..

to use remoting you can do:::


first create a project and name it BusinesssObject for example..
add to it a class name it Clas..

here is the code for it:

using System;
using System.IO;
using System.Collections;

namespace BusinessObject
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      public class Clas : System.MarshalByRefObject
      {
            public bool checking=false;
            public Clas()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }


            public bool Check()
            {
                  if(checking==true)
                  {
                        return true;
                  }
                  else
                  {
                        return false;
                  }
            }
      }
}

in this class i created a checking function that returns true or false...
build the project..

in the same solution create a project name it host
add reference to the host project..(right click references and click add reference choose projects tab and choose BusinessObject project and addit..

also add refernce to System.Runtime.Remoting from the .NET tab

then add to this project a class name it class

here is the code:

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using BusinessObject;
using System.IO;
using System.Collections;

namespace Host
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            //[STAThread]
            static void Main(string[] args)
            {
                  //
                  // TODO: Add code to start application here
                  //
                  Console.WriteLine("Host: started");
                  TcpChannel tcp =new TcpChannel(7777);
                  ChannelServices.RegisterChannel(tcp);
                  Clas s = new Clas();
                  RemotingServices.Marshal(s, "Clas");
                  string tst=Console.ReadLine();
                  while(tst.ToLower()!="exit")
                  {
                        s.checking=true;
                        tst=Console.ReadLine();
                        s.checking=false;
                  }
            
                  
            }
      }
}

then create another third project name it client: add also a reference to BusinessObject and add refernce to System.Runtime.Remoting

create a form name it form1 code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.Remoting;
using BusinessObject;
using System.IO;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Drawing.Drawing2D;

namespace Client
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            const string URL = "tcp://localhost:7777/Clas";

            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Label label1;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.button1 = new System.Windows.Forms.Button();
                  this.label1 = new System.Windows.Forms.Label();
                  this.SuspendLayout();
                  //
                  // button1
                  //
                  this.button1.Location = new System.Drawing.Point(240, 120);
                  this.button1.Name = "button1";
                  this.button1.TabIndex = 0;
                  this.button1.Text = "button1";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // label1
                  //
                  this.label1.Location = new System.Drawing.Point(208, 48);
                  this.label1.Name = "label1";
                  this.label1.TabIndex = 1;
                  this.label1.Text = "label1";
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(608, 286);
                  this.Controls.Add(this.label1);
                  this.Controls.Add(this.button1);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  Clas g =new Clas();
                  g = (Clas)RemotingServices.Connect(typeof(Clas), URL);
                  if(!g.Check())
                  {      
                        label1.Text="Printed";                
                  }
                  else
                  {
                        MessageBox.Show("Job Stopped");
                        Application.Exit();
                  }
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
            
            }

      

      
      }
}

the idea of this simple program.. is that the hot will start...then   wait for any key...the client then starts...it will allow any press on the button untill the key is pressed on the host...

when a key is pressed on the host the value of checking will be true and thus the checking will return true...

to achieve that you will have first run the host from the .exe application from the bin then run the client..

concentrate on this :::::


in the BusinessObject class you should inherit : System.MarshalByRefObject

in the host class you should have:

TcpChannel tcp =new TcpChannel(7777);//7777 specify the port the client will use
ChannelServices.RegisterChannel(tcp);
Clas s = new Clas();
RemotingServices.Marshal(s, "Clas");

and in the client:

you should have:

const string URL = "tcp://localhost:7777/Clas"; // or the ip of the computer instead localhost

Clas g =new Clas();
g = (Clas)RemotingServices.Connect(typeof(Clas), URL);
g.Check();//then you can use any function from the business object..


cheers





0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question