473,559 Members | 2,982 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 1549
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
1352
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??...
5
1326
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
1482
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...
1
1153
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. ...
0
7629
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...
0
7550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7836
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. ...
1
7593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6184
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...
1
5455
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...
0
3579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2046
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
0
872
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.