Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / April 2006

Tip: Looking for answers? Try searching our database.

Passing Object to Server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Quin - 22 Apr 2006 22:01 GMT
I have a client that creates a remoteable server object,
"serverobject", and can pass strings.  The client creates
a "clientobject" to pass to the server, as:

serverobject.pass(clientobject)

This fails with the following:

Because of security restrictions, the type
System.Runtime.Remoting.ObjRef cannot be accessed.
Spam Catcher - 23 Apr 2006 08:07 GMT
"Quin" <QuinP@dennisusa.com> wrote in news:eODRt$kZGHA.4248
@TK2MSFTNGP05.phx.gbl:

> I have a client that creates a remoteable server object,
> "serverobject", and can pass strings.  The client creates
> a "clientobject" to pass to the server, as:
>
> serverobject.pass(clientobject)

Did you inherit MarshalObjectByRef in the client object?

Also, is the client object delcare in a common interface shared by
client/server?
Quin - 23 Apr 2006 20:44 GMT
> "Quin" <QuinP@dennisusa.com> wrote in news:eODRt$kZGHA.4248
> @TK2MSFTNGP05.phx.gbl:
[quoted text clipped - 9 lines]
> Also, is the client object delcare in a common interface shared by
> client/server?

Yes, the client object inherits MarhsalObjectByRef.  The
Server project has a reference to the client project.
Quin - 23 Apr 2006 23:25 GMT
> "Quin" <QuinP@dennisusa.com> wrote in news:eODRt$kZGHA.4248
> @TK2MSFTNGP05.phx.gbl:
[quoted text clipped - 9 lines]
> Also, is the client object delcare in a common interface shared by
> client/server?

Both projects reference each other and System.Remoting

Here is the Client Code:

using System;
using System.Collections.Generic;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Text;
using HServer;

namespace HClient
{
   class Program
   {
       static void Main(string[] args)
       {
           Console.WriteLine("HClient");

           //Create the Channel, Register
           TcpChannel clientChannel = new TcpChannel();
           ChannelServices.RegisterChannel(clientChannel, false);

           //Register for Remote Object
           WellKnownClientTypeEntry remoteType = new
WellKnownClientTypeEntry(
               typeof(HelloServer),
               "tcp://localhost:9090/HelloServer");

RemotingConfiguration.RegisterWellKnownClientType(remoteType);

           //Create Remote object and call
           HelloServer hs = new HelloServer();
           hs.SendString("String from HClient");   //Send String
           Console.WriteLine("String sent, hit any key to continue");
           Console.Read();
           
           //Create obj and send
           HelloClient hc = new HelloClient();
           hs.SendObj(hc);

           Console.WriteLine("HClient, waiting to exit, hit any key");
           Console.Read();
       }
   }

   public class HelloClient : MarshalByRefObject
   {
       public void ReceiveString(string myString)
       {
           Console.WriteLine(myString);
       }
   }
}

Signature

Here is the Server Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using HClient;

namespace HServer
{
   class Program
   {
       static void Main(string[] args)
       {
           Console.WriteLine("HServer");

           //Create and Register Channel
           TcpChannel serverChannel = new TcpChannel(9090);
           ChannelServices.RegisterChannel(serverChannel, false);

           //Expose Remote Object

RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloServer),
               "HelloServer", WellKnownObjectMode.Singleton);

           //Hang a Read
           Console.WriteLine("Hit any key to exit!");
           Console.Read();
       }
   }

   public class HelloServer : MarshalByRefObject
   {
       public void SendObj(HelloClient hc)
       {
           hc.ReceiveString("This String from HelloServer");
       }

       public void SendString(string myString)
       {
           Console.WriteLine(myString);
       }
   }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.