Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Vb.net remoting with interface

Posted on 2006-06-25
5
Medium Priority
?
357 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

597 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