473,756 Members | 5,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

webservices: simple question, accessing webservice members

Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice?
I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
............... ............... ..

So when I consume this webservice, I want to be able to call the sayHello()
method, and have access to the hello2 variable after having called sayHello
() and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Servic e1 ws = new remoteWS.Servic e1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!
Nov 16 '05 #1
5 1570
I don't think you can access a public member of
System.Web.Serv ices.WebService class from a client side. I would either
stored the value in database or use Session in the web service.

Good luck!

=============== =============
Hayato Iriumi (hi*****@hotmai l.com)
Blog: http://www.vbaspcoder.com
"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
............... ............... .

So when I consume this webservice, I want to be able to call the sayHello() method, and have access to the hello2 variable after having called sayHello () and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Servic e1 ws = new remoteWS.Servic e1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!

Nov 16 '05 #2
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.

For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Serv ices.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by
the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
............... ............... .

So when I consume this webservice, I want to be able to call the sayHello() method, and have access to the hello2 variable after having called sayHello () and thus expecting the "hello2" variable to contain the "another hello
to you!" value:
remoteWS.Servic e1 ws = new remoteWS.Servic e1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!

Nov 16 '05 #3
I screwed up a bit of that code.

Please replace the client class as follows:

public void MyClient()
{
Service1 mywebservice;
SharedClass myShared;
myShared = mywebservice.Sa yHello();
Console.WriteLi ne("{0}", myShared.MyHell o1);
Console.WriteLi ne("{0}", myShared.MyHell o2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:GKomd.5134 23$mD.491984@at tbi_s02...
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.
For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Serv ices.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
Hi, (new to webservices here)

Is it possible to access a class instance variable defined in a

webservice?
I want to access this variable, in addition to the data being returned by the [webmethod].

so let's say I have the following webservice class:
public class Service1 : System.Web.Serv ices.WebService
{

public string hello2;

public ModelServices()
{
InitializeCompo nent();
}

[WebMethod]
public string sayHello()
{
hello2 = "another hello to you!"
return "hello there";
}
}
............... ............... .

So when I consume this webservice, I want to be able to call the

sayHello()
method, and have access to the hello2 variable after having called

sayHello
() and thus expecting the "hello2" variable to contain the "another hello to you!" value:
remoteWS.Servic e1 ws = new remoteWS.Servic e1();
string hello1 = ws.sayHello();
string hello2 = ws.hello2;

Is this possible, and how do I go about doing it? thanks!


Nov 16 '05 #4
"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in news:q9pmd.4640 4
$5K2.39317@attb i_s03:
I screwed up a bit of that code.

Please replace the client class as follows:

public void MyClient()
{
Service1 mywebservice;
SharedClass myShared;
myShared = mywebservice.Sa yHello();
Console.WriteLi ne("{0}", myShared.MyHell o1);
Console.WriteLi ne("{0}", myShared.MyHell o2);
}

Sorry about that.

--- Nick

"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:GKomd.5134 23$mD.491984@at tbi_s02...
you can either add another webmethod to return the new value (which is
chatty and inefficient) or you can return a class that contains both values.

For example:

public class SharedClass
{
string MyHello1;
string MyHello2;
}

public class Service1: System.Web.Serv ices.WebService
{
// put initializer here... ommitted for brevity
[WebMethod]
public SharedClass SayHello()
{
SharedClass sc = new SharedClass();
sc.MyHello1 = "Hello There";
sc.MyHello2 = "And Again";
}
}

public class WebClient
{
public void MyClient()
{
Service1 mywebservice;
mywebservice.Sa yHello();
Console.WriteLi ne("{0}", mywebservice.My Hello1);
Console.WriteLi ne("{0}", mywebservice.My Hello2);
}
}

((Caveat: this code is from the top of my head... it has not been
compiled... please excuse typos))

Hope this helps,
--- Nick

"hellrazor" <jo***@anothe r-world.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
> Hi, (new to webservices here)
>
> Is it possible to access a class instance variable defined in a

webservice?
> I want to access this variable, in addition to the data being
returned by > the [webmethod].
>
> so let's say I have the following webservice class:
>
>
> public class Service1 : System.Web.Serv ices.WebService
> {
>
> public string hello2;
>
> public ModelServices()
> {
> InitializeCompo nent();
> }
>
> [WebMethod]
> public string sayHello()
> {
> hello2 = "another hello to you!"
> return "hello there";
> }
> }
>
>
> ............... ............... .
>
> So when I consume this webservice, I want to be able to call the

sayHello()
> method, and have access to the hello2 variable after having called

sayHello
> () and thus expecting the "hello2" variable to contain the "another hello > to you!" value:
>
>
> remoteWS.Servic e1 ws = new remoteWS.Servic e1();
> string hello1 = ws.sayHello();
> string hello2 = ws.hello2;
>
>
>
> Is this possible, and how do I go about doing it? thanks!
>
>




Hi there, thanks!

When I try to compile the client application in VS, I get the following
error:

C:\clients\test .cs(1070): Cannot implicitly convert type
'WS.ReturnValue sClass' to 'MyApp.ReturnVa luesClass'
I have placed the class in the source code for both the webservice and
the client. Is there anything specific involved that I have missed?

Thanks!

Jorge
Nov 16 '05 #5
<clip ...>
Hi there, thanks!

When I try to compile the client application in VS, I get the following
error:

C:\clients\test .cs(1070): Cannot implicitly convert type
'WS.ReturnValue sClass' to 'MyApp.ReturnVa luesClass'
I have placed the class in the source code for both the webservice and
the client. Is there anything specific involved that I have missed?

Thanks!

Jorge


Hi Jorge,

That's what I get for not compiling the code first. My apologies.

The shared class should NOT be declared again in the client code. The
definition of the shared class is passed via the WSDL and is coded in the
web service generated code. You can simply declare a variable of type
WS.ReturnValues Class and refer to the members that way.

If you want to see the code the Visual Studio generates for you when you
make a web reference, then look carefully at your project explorer window.
There are a couple of small icons in the bar just above the treeview of your
solution and project(s). One of the icons, if you hover over it, says
something like "show all files". Click it. Then look into the client
project. You will see a new code file under the web reference to the web
service. In there, you will see the definition of the shared class.

Good Luck,
--- Nick
Nov 16 '05 #6

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

Similar topics

1
1361
by: Jinashe | last post by:
what do i need to enable accessing of webservices from a clients PC i'm hosting some webservices from my server in VB.NET. i've got some client windows applications done in VB.NET. what have i got to install on the clients PC to be able to access these webservices?? Will just the .NET Framework suffice??? Or do i have to install SOAP?? note - the OS of the client can be win98, win2K, win3000, winXP
5
1331
by: hellrazor | last post by:
Hi, (new to webservices here) Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by the . so let's say I have the following webservice class: public class Service1 : System.Web.Services.WebService
1
1495
by: WStoreyII | last post by:
Two question, 1) is there a way to edit the interface of the display for when accessing a asmx file through the browser as opposed to that default web service interface. For example what if i wanted to use a dropdown list for one of the paramaters. if this is possible how html, xslt ? 2) can i assign a xslt style sheet to a xml webservices output. Lile instead of accessing the webservice from code. THe user can access the
1
1159
by: Jothi | last post by:
Hi, We are a small application development group. We have about 100 Users who primarily use Microsoft Related Products. Our Application Development was purley based on a CLient Server Model using Visual Basic and SQL Server. We plan to move forward to the .NET environment. We plan to develop applications with ASP.NEt as well as VB.NET. Right now we have some COM components or DLL's that we use. For example we
0
9454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10028
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9868
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9707
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6533
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3804
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 we have to send another system

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.