473,503 Members | 5,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to pass objects as parameter to remoting object methods?

Hi All!
Probably my question is newbie but anycase.
Should I do object that I want to pass as parameter to remoting object serializable?

For Example:

//server

public class MyServerObject
{
Settings settings = Settings.Instance();

public static void Main()
{
settings.Restore();
//Initialize TCP channel and Remoting object
//channel properties
IDictionary props = new Hashtable();
props["name"] = "Channel1";
props["port"] = settings.getServerPort();
//create channel
TcpChannel channel = new TcpChannel(props, null, new BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(MyRemotingObject ),
"ServerUri", WellKnownObjectMode.Singleton);
}
}
//client
public class MyClientObject
{
Settings settings = Settings.Instance();
public static void Main()
{
this.settings.Restore();
string serverUri = "tcp://" + settings.getServerAddress() + ":" + settings.getServerPort() + "/ServerUri";
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
serverObject = (MyRemotingObject) Activator.GetObject(typeof(MyRemotingObject), serverUri);
if (serverObject == null) LoggingProcessor.Error("Could not locate server");

//do something
ServiceObject serviceObject = new ServiceObject();
serviceObject.str1 = "this is a string";
serviceObject.num1 = 12;
serverObject.myMethod(serviceObject);

}
}
//remitong object
public class MyRemotingObject : MarshalByRefObject
{
public void myMethod(MySomeObject myObject)
{
// do somethinng
}
}

//service object
public class ServiceObject
{
public string str1;
public int num1;
public int num2
}

In given case I got following error:

An unhandled exception of type 'System.Runtime.Serialization.SerializationExcepti on' occurred in mscorlib.dll
Additional information: The type SES.Tools.General.Queue in Assembly Tools, Version=1.0.1934.2848, Culture=neutral, PublicKeyToken=null is not marked
as serializable.

I tried declare ServiceObject as [Serializable] and got following error:

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Any ideas?
Nov 17 '05 #1
3 6708
Gelios,

It says the Queue object is not serializable (and the definition is not
shown here), which makes me think that the class that you tagged as
[Serializable] has members that must be serializable as well. That error
makes me think that there are fields that are not. Make sure that the
fields are all serializable, and i should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Gelios" <ge****@rbcmail.ru> wrote in message
news:d3***********@gavrilo.mtu.ru...
Hi All!
Probably my question is newbie but anycase.
Should I do object that I want to pass as parameter to remoting object
serializable?

For Example:

//server

public class MyServerObject
{
Settings settings = Settings.Instance();

public static void Main()
{
settings.Restore();
//Initialize TCP channel and Remoting object
//channel properties
IDictionary props = new Hashtable();
props["name"] = "Channel1";
props["port"] = settings.getServerPort();
//create channel
TcpChannel channel = new TcpChannel(props, null, new
BinaryServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel);

RemotingConfiguration.RegisterWellKnownServiceType (typeof(MyRemotingObject
),
"ServerUri", WellKnownObjectMode.Singleton);
}
}
//client
public class MyClientObject
{
Settings settings = Settings.Instance();
public static void Main()
{
this.settings.Restore();
string serverUri = "tcp://" + settings.getServerAddress() + ":" +
settings.getServerPort() + "/ServerUri";
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
serverObject = (MyRemotingObject)
Activator.GetObject(typeof(MyRemotingObject), serverUri);
if (serverObject == null) LoggingProcessor.Error("Could not locate
server");

//do something
ServiceObject serviceObject = new ServiceObject();
serviceObject.str1 = "this is a string";
serviceObject.num1 = 12;
serverObject.myMethod(serviceObject);

}
}
//remitong object
public class MyRemotingObject : MarshalByRefObject
{
public void myMethod(MySomeObject myObject)
{
// do somethinng
}
}

//service object
public class ServiceObject
{
public string str1;
public int num1;
public int num2
}

In given case I got following error:

An unhandled exception of type
'System.Runtime.Serialization.SerializationExcepti on' occurred in
mscorlib.dll
Additional information: The type SES.Tools.General.Queue in Assembly
Tools, Version=1.0.1934.2848, Culture=neutral, PublicKeyToken=null is not
marked as serializable.

I tried declare ServiceObject as [Serializable] and got following error:

An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll
Additional information: Index (zero based) must be greater than or equal
to zero and less than the size of the argument list.

Any ideas?

Nov 17 '05 #2
Nicholas Paldino [.NET/C# MVP] wrote:
Gelios,

It says the Queue object is not serializable (and the definition is not
shown here), which makes me think that the class that you tagged as
[Serializable] has members that must be serializable as well. That error
makes me think that there are fields that are not. Make sure that the
fields are all serializable, and i should work.

Hope this helps.


First of all thanks.
I think so too, but it is clear to me.
I showed Queue object as ServiceObject example.
Below real definition:

using System;

namespace SES.Tools.General
{
/// <summary>
/// Summary description for Queue.
/// </summary>
public class Queue
{
public int queueId;
public string description;
public string email;
public int ruleId;

public override string ToString()
{
return description;
}

}
}

Am I understand you correct? I should this object serializable?
Nov 17 '05 #3
If you want to take the object over "by value" - in other words get a copy of it to the server then mark it as [Serializable]. If you want to pass it "by reference" so that the server gets a proxy to the object amd all calls to it are remoted back to to the client, derive from MarshalByRefObject. I'd recommend the first from looking at the object in question.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

First of all thanks.
I think so too, but it is clear to me.
I showed Queue object as ServiceObject example.
Below real definition:

using System;

namespace SES.Tools.General
{
/// <summary>
/// Summary description for Queue.
/// </summary>
public class Queue
{
public int queueId;
public string description;
public string email;
public int ruleId;

public override string ToString()
{
return description;
}

}
}

Am I understand you correct? I should this object serializable?

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2840
by: lawrence | last post by:
The following class method is being rejected by the PHP parser. If I change the method paramaters and allow the objects to be passed as copies, then the parser has no problem. Or, if I pass by...
0
884
by: Lloyd Sheen | last post by:
Sorry about the length of this post but I felt it was better to show all the details in order to get some resolution. I have the following senario: - a service which hosts objects for remoting...
2
4701
by: Mountain Bikn' Guy | last post by:
It is known that one cannot pass arguments as ref or out in a marshal-by-reference class. My problem is that I have a C DLL (and C# wrapper) that I need to isolate in an AppDomain and then I need...
3
5464
by: Brett | last post by:
I have several classes that create arrays of data and have certain properties. Call them A thru D classes, which means there are four. I can call certain methods in each class and get back an...
10
2487
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
14
9800
by: Derek Basch | last post by:
This one has always bugged me. Is it better to just slap a "self" in front of any variable that will be used by more than one class method or should I pass around variable between the methods? ...
4
146528
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
13
3000
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
12
11005
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.