RE: webservices: simple question, accessing webservice members
From: Dan Rogers (danro_at_microsoft.com)
Date: 11/16/04
- Next message: Dan Rogers: "RE: Recommendations for securing a 'local' webservice."
- Previous message: Dan Rogers: "RE: Referencing web service"
- In reply to: hellrazor: "webservices: simple question, accessing webservice members"
- Next in thread: Hayato Iriumi: "Re: webservices: simple question, accessing webservice members"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 16 Nov 2004 01:23:39 GMT
Hi Jorge,
As you've already found out, the code you showed works fine. What you are
trying to do, however, is to implement static or shared data (singleton)
behaviors across all instances of a service method call. As such, the code
you are trying will not work between method invocations - but it WILL work
for a single method invocation.
The web service class you write is a facade of sorts that lets a stateless
method call be dispatched from a remote caller. As such, a new instance of
the web service class is implemented for each method call. You can prove
this by putting a debug break point on the IntializeComponent call in the
constructor. Each time any service method is invoked, the constructor is
called - which means that each call to the web service entry point cause a
new invocation of the class to be constructed.
To get a shared data behavior, you either have to implement applicaiton
state (within IIS) or use some other successful singleton pattern
implementation outside of your web service class. This could be a
database, a COM+ component, or some other in memory persistent store that
you can access from your own code.
I hope this helps,
Dan Rogers
Microsoft Corporation
--------------------
>Subject: webservices: simple question, accessing webservice members
>From: hellrazor <jorge@another-world.com>
>Organization: packet monkeys inc.
>Message-ID: <Xns95A2AE03D3856jorgeanotherworldcom@207.46.248.16>
>User-Agent: Xnews/5.04.25
>Newsgroups:
microsoft.public.dotnet.languages.csharp,microsoft.public.dotnet.framework.w
ebservices,microsoft.public.dotnet.framework.aspnet.webservices
>Date: Mon, 15 Nov 2004 17:01:25 -0800
>NNTP-Posting-Host: s0106000625d84bd8.vn.shawcable.net 24.86.11.226
>Lines: 1
>Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
phx.gbl
>Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7454
microsoft.public.dotnet.framework.aspnet.webservices:26582
microsoft.public.dotnet.languages.csharp:286847
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
>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.Services.WebService
> {
>
> public string hello2;
>
> public ModelServices()
> {
> InitializeComponent();
> }
>
> [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.Service1 ws = new remoteWS.Service1();
>string hello1 = ws.sayHello();
>string hello2 = ws.hello2;
>
>
>
>Is this possible, and how do I go about doing it? thanks!
>
>
>
- Next message: Dan Rogers: "RE: Recommendations for securing a 'local' webservice."
- Previous message: Dan Rogers: "RE: Referencing web service"
- In reply to: hellrazor: "webservices: simple question, accessing webservice members"
- Next in thread: Hayato Iriumi: "Re: webservices: simple question, accessing webservice members"
- Messages sorted by: [ date ] [ thread ]