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 / ASP.NET / Web Services / May 2005

Tip: Looking for answers? Try searching our database.

Problem with parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin - 18 May 2005 17:52 GMT
Hi all,

I have a Webservice in C#, I call this webservice function with a parameter
as String object (named pMessage)
In the function the String object pMessage will be set to corresp. messsage.
But in client program, this parameter is unchanged. Why? How can I do?

The code is following:
[Web ...]
public bool xxx(String pMessage)
{
   if (..)
       pMessage = " 111";
   else
       pMessage = " 222";
}

Client:

String sMsg = "";
webservice1.xxx(sMsg);
MessageBox.show(sMsg);

Thanks
Martin
Chad Z. Hower aka Kudzu - 18 May 2005 18:50 GMT
> messsage. But in client program, this parameter is unchanged. Why? How
> can I do?
>
> The code is following:
> [Web ...]
> public bool xxx(String pMessage)

Of course, this is a by VALUE reference, not a byref.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Martin - 18 May 2005 19:19 GMT
Hi,
what do you think about?

I think, when I pass a String Object to a function, the function can change
its value, properties, these changes are made to the original object.

I have tried with "public bool xxx( ref String pMessage)", But it is the
same result.
I think, in this case, byref means, the function can change the reference to
another String Object (in C++ is this corresp. to pointer, point to another
object?)

Otherwise, I understood, byval, in, out have meaning only with the primitive
type.

> > messsage. But in client program, this parameter is unchanged. Why? How
> > can I do?
[quoted text clipped - 10 lines]
>
> Blog: http://blogs.atozed.com/kudzu
Chad Z. Hower aka Kudzu - 19 May 2005 05:45 GMT
> I think, when I pass a String Object to a function, the function can
> change its value, properties, these changes are made to the original
> object.

No.

   private void Test(string x) {
     x = "Hello";
   }

   private void button1_Click_1(object sender, System.EventArgs e) {
     string y = "Bye";
     Test(y);
     button1.Text = y;
   }

button1 says Byte, not Hello.

This makes it say Bye:

   private void Test(ref string x) {
     x = "Hello";
   }

   private void button1_Click_1(object sender, System.EventArgs e) {
     string y = "Bye";
     Test(ref y);
     button1.Text = y;
   }

> I have tried with "public bool xxx( ref String pMessage)", But it is the
> same result.

Webservices AFAIK dont support ref parameters. I think they support out
parameters though, you can try:

bool(string InString, out string OutString);

> I think, in this case, byref means, the function can change the
> reference to another String Object (in C++ is this corresp. to pointer,
> point to another object?)

Essentially.

> Otherwise, I understood, byval, in, out have meaning only with the
> primitive type.

No, its can effect objects too. Strings are immutable, so any change you
make makes a NEW string. So if you pass the object byval, there are now two
objects, and the first is not the same as the reference holder to the new
one.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
Martin - 19 May 2005 09:12 GMT
Thanks

> Webservices AFAIK dont support ref parameters. I think they support out
> parameters though, you can try:
>
> bool(string InString, out string OutString);

I had tried this way, before I asked newsgroup. But I call this method
false:
bool login(..., out string sMessage)

login(..., sMessage);

Now I wrote:
login(..., out sMessage);

Thanks again

> > I think, when I pass a String Object to a function, the function can
> > change its value, properties, these changes are made to the original
[quoted text clipped - 53 lines]
>
> Blog: http://blogs.atozed.com/kudzu
Ravichandran J.V. - 19 May 2005 08:25 GMT
you need a lvalue to call a function and anyway, change the return type of
the webservice method to string so as to receive a string from the web
service.

with regards,

J.v.

> Hi all,
>
[quoted text clipped - 21 lines]
> Thanks
> Martin

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.