473,785 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Webservice class recreation...

Hi,

I don't know if this is a stupid question, but I observe that my webservice
is created for each call to a webmethod. More precisely an instance of the
webservice class is created for each call. This makes the
InitializeCompo nent() method run for each method call and seems to really
slow things down. Can I keep the webservice object running after a method
call?

Trygve
Nov 21 '05 #1
3 2157

"Trygve Lorentzen" <trygveloAThald enDOTnet> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
Hi,

I don't know if this is a stupid question, but I observe that my webservice is created for each call to a webmethod. More precisely an instance of the
webservice class is created for each call. This makes the
InitializeCompo nent() method run for each method call and seems to really
slow things down. Can I keep the webservice object running after a method
call?


This is the way it works: since Web Services are (supposed to be) stateless,
a new instance is created on every call.

If you have some heavy initialization to do that you want to do only once,
do the initialization from within the Application_Sta rt handler in the
Global class.

Regards,
Sami
Nov 21 '05 #2
Hi,

thanks you so much for your answer. I think I have done quite a few design
mistakes when creating my webservice. My webservice is mostly returning
typed datasets with data from a database. I have one webservice file:
data.asmx with database connection, dataadapters and datasets and methods to
return datasets to the client and save data in datasets from the client to
the database. Do you have any advice for me for a better way to design this
application? I understand I should move the database connection to the
global file, but what about dataadapters and datasets? It would be faster to
initialize those only once too I suppose. Hence the data.asmx would only
contain the functions to work with the datasets from the global file.

How do I work with objects from the global.asax file in data.asmx? Can I
reference them as local objects?

Thank you so much for your time and answers! I hope you are willing to share
your knowledge with me :)

Cheers,
Trygve

"Sami Vaaraniemi" <sa**********@p leasejippii.fi> wrote in message
news:u$******** ******@tk2msftn gp13.phx.gbl...

"Trygve Lorentzen" <trygveloAThald enDOTnet> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
Hi,

I don't know if this is a stupid question, but I observe that my webservice
is created for each call to a webmethod. More precisely an instance of the webservice class is created for each call. This makes the
InitializeCompo nent() method run for each method call and seems to really slow things down. Can I keep the webservice object running after a method call?


This is the way it works: since Web Services are (supposed to be)

stateless, a new instance is created on every call.

If you have some heavy initialization to do that you want to do only once,
do the initialization from within the Application_Sta rt handler in the
Global class.

Regards,
Sami

Nov 21 '05 #3
"Trygve Lorentzen" <trygveloAThald enDOTnet> wrote in message
news:e8******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

thanks you so much for your answer. I think I have done quite a few design
mistakes when creating my webservice. My webservice is mostly returning
typed datasets with data from a database. I have one webservice file:
data.asmx with database connection, dataadapters and datasets and methods to return datasets to the client and save data in datasets from the client to
the database. Do you have any advice for me for a better way to design this application? I understand I should move the database connection to the
global file, but what about dataadapters and datasets? It would be faster to initialize those only once too I suppose. Hence the data.asmx would only
contain the functions to work with the datasets from the global file.

How do I work with objects from the global.asax file in data.asmx? Can I
reference them as local objects?

Thank you so much for your time and answers! I hope you are willing to share your knowledge with me :)

Cheers,
Trygve


Are you using SqlClient classes for database access? If so, then the
recommended practice is to create a new SqlConnection object on every web
method call, use it and close it when you are done. SqlConnection class
already does connection pooling so that you don't have to try and keep it
around accross requests.

It is likely that the overhead of creating and initializing the dataadapters
and datasets is negligible compared to the time it takes to do e.g., network
access. Unless you have actually made measurements and are sure that this is
a performance bottleneck, don't bother trying to optimize it.

If you do have something that would benefit from being initialized once in
Application_Sta rt, then you can use the Application object as global store.
Alternatively you could use static (shared) members too. In both cases you
will need to make sure that you access them in thread safe manner. For more
information about global state in web apps, see

http://msdn.microsoft.com/library/de...ationstate.asp

Regards,
Sami
Nov 21 '05 #4

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

Similar topics

5
1571
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
6
768
by: Davie | last post by:
I want to authorise a user of a web service by using the AuthHeaderValue for some reason I keep getting a null reference exception when I try to run the following code: It seems to work fine on a .NET Framework application, but just not on the .NET CF version. Can anyone suggest anything that might be wrong with the code? (I could post the app and webservice, but i was hoping that you might have noticed something from the supplied...
2
1331
by: Sergi Adamchuk | last post by:
I need determine which web service (class WebService or its inheritors) serveces current request (I need Type instance of class that serves request). For example you wrote your own WebService: public class MyService : WebService .... Now I need to know the Guid of WebService class that serves current
11
3958
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to handle most of the things. Currently I have a class called "Product" sitting my webserivce like the following: Code:
7
5405
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
8
4195
by: Topper | last post by:
Hello. I have simple web folders structure: -ROOT - BIN WebService.dll WebService.asmx I need to use my WebService.dll not in bin folder - for example, in ROOT. How do i this? How can i do this without .config file only with some configuration
7
2928
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure out to create a "DataSet" as the return type from the webservice?
5
3799
by: AliR | last post by:
Hi Everyone, I have a Visual C++ MFC program, and I am trying to use a webservice written in C#. When I add the webservice to my project using Add Web Reference the sproxy compiler complains about one of the object wanting to extend MarshalByRefObject object, and I get an error SDL1030. I can use the webservice in a C# project just fine but not the C++. Can anyone help me out with this?
2
1469
by: Jannicke | last post by:
Hi. I have a project that contains a webservice. To test my webservice I have another class in the same project. In the project I have added a webreference to my webservice. In my class file i call the webservice which should return a string value in the response. The problem is that the responsevalue is null even if the webmethod acts like it should do. I have debugged my code and when i debug the webmethod the return value is set correct,...
0
9645
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
9480
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7500
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
6740
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
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.