473,503 Members | 4,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass by reference to a WebService

Hi folks,

I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.

The thing that troubles me about pass-by-reference into a WebService is that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type will
be place some value at that address, however, the address is now on the
Server machine...how can it set the local machine objcet address if the
location is different?

Is this correct? Or does .NET WebServices wrap up this functionality to
allow it in some special way? Or am I missing something?

Thanks for any views, insights,

Best Regards,
David
Aug 17 '06 #1
5 7801
"David++" wrote:
Hi folks,

I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.

The thing that troubles me about pass-by-reference into a WebService is that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type will
be place some value at that address, however, the address is now on the
Server machine...how can it set the local machine objcet address if the
location is different?

Is this correct? Or does .NET WebServices wrap up this functionality to
allow it in some special way? Or am I missing something?

Thanks for any views, insights,

Best Regards,
David
I performed a little test with a web service running locally. It seemed to
work fine when passing by reference using the 'ref' keyword i.e.

// In the web service code..
[WebMethod]
public void PassByRef(ref string s)
{
s = "This is pass-by-reference";
}

// In the client code..
string s = "";

Service service = new Service();

service.PassByRef(ref s);
MessageBox.Show(s); // outputs 'This is pass-by-reference'

Using the 'out' keyword behaved a little more unusual than was expected -
// In the web service code..
[WebMethod]
public void PassByOut(out string s)
{
s = "This is pass-by-out";
}

// In the client code..
s = service.PassByOut();
MessageBox.Show(s); // outputs 'This is pass-by-out'

Note that the WebMethod PassByOut is a void function yet it is treated as
function which returns a string and takes no parameter...which is
strange...this must be how .NET handles this situation? Compared to the
traditional use of 'out' when using a local function -

// In the client code...
private void Method(out string s)
{
s = "This is a local method";
}

// In the client code...
Method(out s);
MessageBox.Show(s); // outputs - 'This is a local method'

Now the method call takes an out parameter and doesnt return anything as
would be expected, which is different from the WebMethod version. Strange and
interesting.
Aug 17 '06 #2
Because the data passed by a web service is serialized it's inherently
a copy of your object that travels across the wire - which is anologous
with ByVal.

Sadly, there's no way around this using web services but web services
deal with messages and aren't a 'remote objects' implementation.

If you change the data in your client, you're changing your local copy.
The server will never know about it unless you create a way to 'push'
the changes back across.
David++ wrote:
"David++" wrote:
Hi folks,

I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.

The thing that troubles me about pass-by-reference into a WebService is that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type will
be place some value at that address, however, the address is now on the
Server machine...how can it set the local machine objcet address if the
location is different?

Is this correct? Or does .NET WebServices wrap up this functionality to
allow it in some special way? Or am I missing something?

Thanks for any views, insights,

Best Regards,
David

I performed a little test with a web service running locally. It seemed to
work fine when passing by reference using the 'ref' keyword i.e.

// In the web service code..
[WebMethod]
public void PassByRef(ref string s)
{
s = "This is pass-by-reference";
}

// In the client code..
string s = "";

Service service = new Service();

service.PassByRef(ref s);
MessageBox.Show(s); // outputs 'This is pass-by-reference'

Using the 'out' keyword behaved a little more unusual than was expected -
// In the web service code..
[WebMethod]
public void PassByOut(out string s)
{
s = "This is pass-by-out";
}

// In the client code..
s = service.PassByOut();
MessageBox.Show(s); // outputs 'This is pass-by-out'

Note that the WebMethod PassByOut is a void function yet it is treated as
function which returns a string and takes no parameter...which is
strange...this must be how .NET handles this situation? Compared to the
traditional use of 'out' when using a local function -

// In the client code...
private void Method(out string s)
{
s = "This is a local method";
}

// In the client code...
Method(out s);
MessageBox.Show(s); // outputs - 'This is a local method'

Now the method call takes an out parameter and doesnt return anything as
would be expected, which is different from the WebMethod version. Strange and
interesting.
Aug 17 '06 #3
Hi David,

I agree with Josh. The following method declaration,

// In the web service code..
[WebMethod]
public void PassByRef(ref string s)
{
s = "This is pass-by-reference";
}

It is the same as this declaration,

// In the web service code..
[WebMethod]
public string PassByRef(string s)
{
return "This is pass-by-reference";
}

The .NET framework creates a proxy using that trick so you do not notice the
difference.

Regards,
Pablo Cibraro.

"Josh Twist" <jo********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Because the data passed by a web service is serialized it's inherently
a copy of your object that travels across the wire - which is anologous
with ByVal.

Sadly, there's no way around this using web services but web services
deal with messages and aren't a 'remote objects' implementation.

If you change the data in your client, you're changing your local copy.
The server will never know about it unless you create a way to 'push'
the changes back across.
David++ wrote:
>"David++" wrote:
Hi folks,

I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.

The thing that troubles me about pass-by-reference into a WebService is
that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type
will
be place some value at that address, however, the address is now on the
Server machine...how can it set the local machine objcet address if the
location is different?

Is this correct? Or does .NET WebServices wrap up this functionality to
allow it in some special way? Or am I missing something?

Thanks for any views, insights,

Best Regards,
David

I performed a little test with a web service running locally. It seemed
to
work fine when passing by reference using the 'ref' keyword i.e.

// In the web service code..
[WebMethod]
public void PassByRef(ref string s)
{
s = "This is pass-by-reference";
}

// In the client code..
string s = "";

Service service = new Service();

service.PassByRef(ref s);
MessageBox.Show(s); // outputs 'This is pass-by-reference'

Using the 'out' keyword behaved a little more unusual than was expected -
// In the web service code..
[WebMethod]
public void PassByOut(out string s)
{
s = "This is pass-by-out";
}

// In the client code..
s = service.PassByOut();
MessageBox.Show(s); // outputs 'This is pass-by-out'

Note that the WebMethod PassByOut is a void function yet it is treated as
function which returns a string and takes no parameter...which is
strange...this must be how .NET handles this situation? Compared to the
traditional use of 'out' when using a local function -

// In the client code...
private void Method(out string s)
{
s = "This is a local method";
}

// In the client code...
Method(out s);
MessageBox.Show(s); // outputs - 'This is a local method'

Now the method call takes an out parameter and doesnt return anything as
would be expected, which is different from the WebMethod version. Strange
and
interesting.

Aug 17 '06 #4
Thanks guys for your answers. Its always good to discover the hidden secrets
of .NET !

Cheers!

David
Aug 18 '06 #5
Sorry, but I don't follow your point.

Of course, you are never going to give one machine the physical address
of variable on another machine (especially in .NET).

When you pass a variable by reference to a web service, the client
marshals the data and sends a copy to the web service. The web service
demarshals it, manipulates it, marshals the new value again and sends
it back. On return from the Web Service call, the client then
demarshals it again and stuffs it back in the original variable. This
is all done transparently so that it behaves virtually like a call by
reference on the local machine.

In this way, passing a parameter ByRef to a web service IS NOT the same
as calling ByVal. True that ultimately you are passing just a copy of
the parameter (not the address), but the end result is that the value
of the variable is changed by the called method like a traditional call
by reference since it is automatically updated on return from the web
service method.

Of course, if you change the value again on the local machine, the web
service won't know about it unless you make another web service call.

Sorry if I misunderstood your post,

-Paul

Josh Twist wrote:
Because the data passed by a web service is serialized it's inherently
a copy of your object that travels across the wire - which is anologous
with ByVal.

Sadly, there's no way around this using web services but web services
deal with messages and aren't a 'remote objects' implementation.

If you change the data in your client, you're changing your local copy.
The server will never know about it unless you create a way to 'push'
the changes back across.
David++ wrote:
"David++" wrote:
Hi folks,
>
I would be interested to hear peoples views on whether or not 'pass by
reference' is allowed when using a Web Service method.
>
The thing that troubles me about pass-by-reference into a WebService is that
essentially we are passing an address of an object which resides on the
'local machine' i.e. a local machine object address. Surely when the
WebService method is called and run 'on the server', the reference type will
be place some value at that address, however, the address is now on the
Server machine...how can it set the local machine objcet address if the
location is different?
>
Is this correct? Or does .NET WebServices wrap up this functionality to
allow it in some special way? Or am I missing something?
>
Thanks for any views, insights,
>
Best Regards,
David
>
I performed a little test with a web service running locally. It seemed to
work fine when passing by reference using the 'ref' keyword i.e.

// In the web service code..
[WebMethod]
public void PassByRef(ref string s)
{
s = "This is pass-by-reference";
}

// In the client code..
string s = "";

Service service = new Service();

service.PassByRef(ref s);
MessageBox.Show(s); // outputs 'This is pass-by-reference'

Using the 'out' keyword behaved a little more unusual than was expected -
// In the web service code..
[WebMethod]
public void PassByOut(out string s)
{
s = "This is pass-by-out";
}

// In the client code..
s = service.PassByOut();
MessageBox.Show(s); // outputs 'This is pass-by-out'

Note that the WebMethod PassByOut is a void function yet it is treated as
function which returns a string and takes no parameter...which is
strange...this must be how .NET handles this situation? Compared to the
traditional use of 'out' when using a local function -

// In the client code...
private void Method(out string s)
{
s = "This is a local method";
}

// In the client code...
Method(out s);
MessageBox.Show(s); // outputs - 'This is a local method'

Now the method call takes an out parameter and doesnt return anything as
would be expected, which is different from the WebMethod version. Strange and
interesting.
Aug 24 '06 #6

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

Similar topics

4
2916
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
5
2944
by: Matthew.DelVecchio | last post by:
hello, i am working w/ a partner company's webservice, which they wrote in java. using a provided webservice.wsdl file, i am able to compile it into a proxy class, webservice.dll. i can add...
2
16590
by: christopherkilmer | last post by:
I've googled my brains out and haven't found the answer yet, so... I have a WebMethod that accepts an array of Order objects as a parameter. I cannot figure out how to send an array to the...
1
1877
by: otto | last post by:
I have a technical question about WebServices. I have a solution with several projects (.exe and .dll). Each project have references to several webservices. I want to know if is possible to create...
6
8998
by: placek | last post by:
Hi all. I would like to create two web services: - The first one - ImportData - should take as an input parameter a XML document and return an integer saying if passed XML document was valid...
2
4685
by: Mark | last post by:
Hi everyone, I have a windows form application that creates a filestream object and then calls my webservice passing the filestream object. I got an error message can't convert windows...
1
5086
by: Tarlanim | last post by:
Hi, i'm looking for a way to pass parameter from a HTML-File to a XML-File. In HTML-File i have a reference to XML-File and i want to use the parametre from the HTML-File in XML-File (Parameter...
3
1796
by: Jerry Spence1 | last post by:
I have a windows based VBNet project and someone has written a small SOAP program that is called FileUpload.asmx. I want to add a reference to this in my project, but when I add a reference the...
4
15038
by: Peter K | last post by:
Hi I have a webservice project in Visual Studio, and another project which uses the webservice. My other project has a web reference to the webservice project, created via Visual Studio by...
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
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.