[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

ref param doesn't keep changes if an exception is thrown (Remoting

Charlie

9/2/2004 1:45:00 AM

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
4 Answers

Sam Santiago

9/2/2004 4:37:00 AM

0

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/cpconremotableo...

You might also want to review:

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

Good luck.

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Charlie" <Charlie@discussions.microsoft.com> wrote in message
news:AB6A0E7A-7B98-458D-9DA8-AAE7A95A1781@microsoft.com...
> 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


Sam Santiago

9/2/2004 9:10:00 PM

0

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
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Charlie" <Charlie@discussions.microsoft.com> wrote in message
news:41FBC96C-9A60-444E-B3C0-D3A11400847D@microsoft.com...
> 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:
>
> > 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/cpconremotableo...
> >
> > You might also want to review:
> >
> > Remoting Overview
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnetremotingoverview.asp?...
> >
> > Good luck.
> >
> > Thanks,
> >
> > Sam
> >
> > --
> > _______________________________
> > Sam Santiago
> > ssantiago@n0spam-SoftiTechture.com
> > http://www.SoftiTe...
> > _______________________________
> > "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> > news:AB6A0E7A-7B98-458D-9DA8-AAE7A95A1781@microsoft.com...
> > > 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
> >
> >
> >


Sam Santiago

9/2/2004 9:28:00 PM

0

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/by...

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Sam Santiago" <ssantiago@n0spam-SoftiTechture.com> wrote in message
news:ez00FFTkEHA.3172@TK2MSFTNGP10.phx.gbl...
> 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
> ssantiago@n0spam-SoftiTechture.com
> http://www.SoftiTe...
> _______________________________
> "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> news:41FBC96C-9A60-444E-B3C0-D3A11400847D@microsoft.com...
> > 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:
> >
> > > 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/cpconremotableo...
> > >
> > > You might also want to review:
> > >
> > > Remoting Overview
> > >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnetremotingoverview.asp?...
> > >
> > > Good luck.
> > >
> > > Thanks,
> > >
> > > Sam
> > >
> > > --
> > > _______________________________
> > > Sam Santiago
> > > ssantiago@n0spam-SoftiTechture.com
> > > http://www.SoftiTe...
> > > _______________________________
> > > "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> > > news:AB6A0E7A-7B98-458D-9DA8-AAE7A95A1781@microsoft.com...
> > > > 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
> > >
> > >
> > >
>
>


Charlie

9/2/2004 11:47:00 PM

0

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:

> 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/by...
>
> Thanks,
>
> Sam
>
> --
> _______________________________
> Sam Santiago
> ssantiago@n0spam-SoftiTechture.com
> http://www.SoftiTe...
> _______________________________
> "Sam Santiago" <ssantiago@n0spam-SoftiTechture.com> wrote in message
> news:ez00FFTkEHA.3172@TK2MSFTNGP10.phx.gbl...
> > 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
> > ssantiago@n0spam-SoftiTechture.com
> > http://www.SoftiTe...
> > _______________________________
> > "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> > news:41FBC96C-9A60-444E-B3C0-D3A11400847D@microsoft.com...
> > > 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:
> > >
> > > > 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/cpconremotableo...
> > > >
> > > > You might also want to review:
> > > >
> > > > Remoting Overview
> > > >
> >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnetremotingoverview.asp?...
> > > >
> > > > Good luck.
> > > >
> > > > Thanks,
> > > >
> > > > Sam
> > > >
> > > > --
> > > > _______________________________
> > > > Sam Santiago
> > > > ssantiago@n0spam-SoftiTechture.com
> > > > http://www.SoftiTe...
> > > > _______________________________
> > > > "Charlie" <Charlie@discussions.microsoft.com> wrote in message
> > > > news:AB6A0E7A-7B98-458D-9DA8-AAE7A95A1781@microsoft.com...
> > > > > 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
> > > >
> > > >
> > > >
> >
> >
>
>
>