Webservice can subscribe to Events?
Given a C# 2005 Web Service project, can the web service respond to Events?
Similar to a VB.NET Windows application might instantiate an ActiveX Objects, via "Dim WithEvents"?
I have a way for a client of the webservice to subscribe to an *Async callback.
However the webservice seems to be more-or-less idle when not being called to do something.
How can I make the webservice "wake itself up" to an extrenal event?
I presume delegates would enter the picture...
Thanks!
Re: Webservice can subscribe to Events?
Hey,
A WebService is designed out of the box to be stateless, so when it isn't being requested to do something, then it isn't doing anything. You can actually see this happening when a call to the Web Service is made it actually calling the initialize code of the Web Service.
Can you provide some context to what exactly you are trying to achieve? I think this would help you to get an answer to your question.
Gary
Re: Webservice can subscribe to Events?
Agreed. However I noticed you can use the static keyword to instantiate objects. The way it works, is when the webservice is started for the first time, these static objects are created, and not destroyed. I am not sure where they live, but they will retain their state for multiple calls to the webservice.
You can instantiate them in your constructor, but do it only if is null, so you only do it once.
My idea is to use a C# delegate to wake up this static object.
I will post some code later too.
Re: Webservice can subscribe to Events?
Here is some sample code - it is in a project I am working on presently. The static Dictionaries are used to store things over long periods of time, for example. I'm doing this in C#. Maybe it could be easier to do this in vb.net, using WithEvents?
Code:
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "**********************")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
#region "Private vars NOTE: SINGLE connection - might have to change"
private SqlConnection MyConnection;
private SqlCommand MyCommand;
private SqlDataReader MyDataReader;
// This static Dictionary keeps track of all currently open sessions
private static Dictionary<String, HMI0Listener> m_hmi0Listeners = new Dictionary<string, HMI0Listener>();
private static Dictionary<String, BinInfo> m_dicBinInfos = new Dictionary<String, BinInfo>();
private static Dictionary<String, BinInfo> m_dicTrackUnloads = new Dictionary<String, BinInfo>();
private static StreamWriter logWriter;
private static int m_hmi0PalletNumber = -1;
private const int MAX_FAIL_NOTIFY_COUNT = 5;
#endregion