ref param doesn't keep changes if an exception is thrown (Remoting
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.remoting.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Charlie (VIP)
Hi again,

Really I need some help or direction on this point. I prepare a
proof-of-concept app to show you my issue. We're trying to move ours custom
services to use remoting architecture, but if i don't find a quick fixed for
this issue, maybe I'll be dead man tomorrow!!

*************************************
************ Server Class ***************
*************************************
public class RemotingService : MarshalByRefObject
{
public RemotingService(){}
public void Execute(ref int i)
{
i = 1;
throw new System.Exception("Remoting Exception...");
}
}

*************************************
************ Client Class ***************
*************************************
class Client
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("Client.exe.config");
RemotingService srv = new RemotingService();
int i = 0;
try { srv.Execute(ref i); }
catch (System.Exception ex) {Console.WriteLine(ex.Message);}

// will be print 0... why not print 1?...
//if the service run locally (Not Remoting) print 1...
Console.WriteLine(i.ToString());
}
}

Just for you information, I'm using a singlecall mode in the web.config file
in the server side.

Tks

--
Carlos Redondo
..Net Developer
Reply to this message...
 
    
Sam Santiago
Passing a parameter as ref will not do the trick. You might want to have a
function vs. a procedure and capture it's return value. Also, you might want
to read this:

Remotable Objects
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconremotableobjects.asp

You might also want to review:

Remoting Overview
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnetremotingoverview.asp?frame=true

Good luck.

Thanks,

Sam

--
_______________________________
Sam Santiago
Click here to reveal e-mail address
http://www.SoftiTechture.com
_______________________________
"Charlie" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Charlie (VIP)
The source code attached in my first request is just a proof-of-concept, in
the real life, I have diferents methods with DataTables and other Data Types
passing by ref, so a function is not a fixed in my case. I have the feeling
that, in a remoting services, when you throw an exception .Net make a
"rollback" or simply don't refresh the objects passing by ref. I need to
confirm this teoria.

"Sam Santiago" wrote:

[Original message clipped]

Reply to this message...
 
    
Sam Santiago
Seems like it. You could always put the code that changes your ref parameter
in a 'finally' block, so that it would be executed even if an exception
occurs. Also, int is an integral type, but I'm not sure how a ref parameter
that is an object will behave in remoting.

Thanks,

Sam

--
_______________________________
Sam Santiago
Click here to reveal e-mail address
http://www.SoftiTechture.com
_______________________________
"Charlie" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> The source code attached in my first request is just a proof-of-concept,
in
> the real life, I have diferents methods with DataTables and other Data
Types
> passing by ref, so a function is not a fixed in my case. I have the
feeling
[Original message clipped]

Reply to this message...
 
    
Sam Santiago
Passing an object by reference in remoting simply reverses the roles of
who's the client and who's the server. Check out this link for an example:

How Do I...Pass An Object to a Server By Reference?
http://samples.gotdotnet.com/quickstart/howto/doc/Remoting/byvalue.aspx

Thanks,

Sam

--
_______________________________
Sam Santiago
Click here to reveal e-mail address
http://www.SoftiTechture.com
_______________________________
"Sam Santiago" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> Seems like it. You could always put the code that changes your ref
parameter
[Original message clipped]

Reply to this message...
 
    
Charlie (VIP)
Well, I tried with finally section, but nothing seems work. I don't have
issues passing by ref param to remoting server side, my issue appear when i
throw an exception because all ref param return with the same data state,
changes applied to the ref params before the throw exception, in the remote
service, are not keep when the control return to the client side... if you
don't throw an exception, everything works fine. In the other, if you don't
define the services as remoting, and run it locally.... With or without throw
exception, the ref params keep the modifications applied in the services
before throws.!!!

Tks a lot for your comments.

"Sam Santiago" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Console
System.Exception
System.MarshalByRefObject
System.Runtime.Remoting.RemotingConfiguration
System.Runtime.Remoting.Services.RemotingService




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com