mjohnson3091 Posted January 20, 2005 Posted January 20, 2005 Hi all, Not sure if this is the right forum but here goes anyway. I'm currently trying out some code to reproduce an application written originally in VB 6 which used ActiveX EXE's. The original application had a client (ActiveX EXE) and Manager (Windows EXE). When a user connected to the Manager it would create a new instance of the Client. I'm trying to do the same in .NET using C#, and using a webservice as the client (not sure if that is the best way, so I'm open to comments on that!). The webservice is very simple and just has one method currently that returns the session number. The Manager (windows application) will, when a button is clicked, attempt to add a new session (create an instance of it) and pass it it's session number. The problem I have is that when I request the session number from any of the instances, it always returns the last sessions number. Manager Code below: //DECLARED AS FOLLOWS: private Client.Session Session1; private Client.Session Session2; //INSTANCIATED AS FOLLOWS Session1 = new Client.Session(); mlngSessions=1; Session1.Initialise(mlngSessions); Session2 = new Client.Session(); mlngSessions=2; Session2.Initialise(mlngSessions); // INFORMATION READ AS FOLLOWS: MessageBox.Show ("Response from Session " + Convert.ToString(Session1.get_SessionNumber()),"MANAGER",MessageBoxButtons.OK,MessageBoxIcon.Information); MessageBox.Show ("Response from Session " + Convert.ToString(Session2.get_SessionNumber()),"MANAGER",MessageBoxButtons.OK,MessageBoxIcon.Information); Client Code Below: private static long mlngSessionNumber; [WebMethod] public bool Initialise(long SessionNumber) { mlngSessionNumber=SessionNumber; return(true); } public long SessionNumber { [WebMethod] get { return mlngSessionNumber; } } Any advice greatly appreciated Quote
IngisKahn Posted January 20, 2005 Posted January 20, 2005 mlngSessionNumber is static therefore every instance you create has access to the same variable. Quote "Who is John Galt?"
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 mlngSessionNumber is static therefore every instance you create has access to the same variable. It needs to be static otherwise it returns 0 everytime. Quote
Administrators PlausiblyDamp Posted January 20, 2005 Administrators Posted January 20, 2005 You may find using session variables are what you need. However if you could give a bit more detail / background on what you are doing there may be an alternative approach to the problem. In most cases you want to minimise (and if possible remove) any state from the server as this will increase scalability and performance while often producing easier to maintain code. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 You may find using session variables are what you need. However if you could give a bit more detail / background on what you are doing there may be an alternative approach to the problem. In most cases you want to minimise (and if possible remove) any state from the server as this will increase scalability and performance while often producing easier to maintain code. Thanks for the reply. I tried to explain in my first post, but I suppose it isn't the easiest thing to explain. Let me try again. In the current VB6 application, we have a manager program (Windows EXE) which handles connections from remote hand-held terminals through sockets. Once a connection is established, we would create an instance of the Client (ActiveX EXE), which then creates it's own connection to a SQL database, so each client can communicate independently. What I'm trying to acheive is the same in .NET using C#. It was my understanding that there isn't such a thing as an ActiveX EXE under .NET, hence the reason for trying to use a webservice. Hope thats a clearer explanation. Quote
Administrators PlausiblyDamp Posted January 20, 2005 Administrators Posted January 20, 2005 What kind of information would the Manager app be passing to the client? Would it require a permanently open connection to the DB or would it be a series of self contained requests? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 What kind of information would the Manager app be passing to the client? Would it require a permanently open connection to the DB or would it be a series of self contained requests? The manager app takes the information from the remote terminals via sockets (normally data scanned from barcodes). it then passes that data to the relevant client instance that processes the data. Each client has a permanently open connection via another lower data layer. Hope that helps. Quote
Administrators PlausiblyDamp Posted January 20, 2005 Administrators Posted January 20, 2005 Web services really work better when no permanent connections are being maintained. Could the Manager app not maintain a constant link to the scanners via sockets (or whatever) and just pass data to the webservice as a parameter to a method. Is there any real need to maintain a permanent session between the manager and the web service (does the associated sessionId have any meaning to the system other than tracking connections)? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 Web services really work better when no permanent connections are being maintained. Could the Manager app not maintain a constant link to the scanners via sockets (or whatever) and just pass data to the webservice as a parameter to a method. Is there any real need to maintain a permanent session between the manager and the web service (does the associated sessionId have any meaning to the system other than tracking connections)? There's no reason why it couldn't have a non-permanent connection. The comms with the webservice is exactly what I want to do as you described, the problem I have is that I want multiple instances of the webservice as I tried to explain in the first post. The problem I get is that the system doesn't seem to do that, or it give unexpected results (like returning the session number of the last session, not the one requested). Quote
Administrators PlausiblyDamp Posted January 20, 2005 Administrators Posted January 20, 2005 You would just have a single instance of the web service and it would handle all requests. Web services do not follow the same conventions as ActiveX exes and as such don't have the concept of running multiple instances; just like you do not have multiple instances of a web site to support browsing by multiple users - the same service fullfills all requests. If you do not require permanent connections or any explicit state management between calls to the webservice / database then there is no need to track or maintain session ids or any other information between method calls. You just need to encapsulate the data you wish to send to the web service either in a class / structure or pass it as a series of parameters to the web service's method; the web service will do it's work and the function returns. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 You would just have a single instance of the web service and it would handle all requests. Web services do not follow the same conventions as ActiveX exes and as such don't have the concept of running multiple instances; just like you do not have multiple instances of a web site to support browsing by multiple users - the same service fullfills all requests. If you do not require permanent connections or any explicit state management between calls to the webservice / database then there is no need to track or maintain session ids or any other information between method calls. You just need to encapsulate the data you wish to send to the web service either in a class / structure or pass it as a series of parameters to the web service's method; the web service will do it's work and the function returns. Ah, thats making more sense.... The complete model is the Manager, Client (Business Services) and a Data Layer. So in this case the Client Webservice would be handling Business Services such as PO Reception in a warehouse, which maybe being carried out by more than one user, and therefore need to keep some kind of state on the current transaction for the current user, hence the reason for using seperate ActiveX Exes in the VB6 version. So what would you suggest would be the best way forward, because one advantage of using the ActiveX exes, was that is one client "died" it didn't affect the whole system. Thanks again for your help on this. I'm new to .NET and it's a little different! Quote
Administrators PlausiblyDamp Posted January 20, 2005 Administrators Posted January 20, 2005 (edited) If a webservice ever 'dies' then it will normally just respawn the worker process and it can start accepting request again, the clients might just have to trap an error and resubmit their data. Not having multiple instances of the app in memory will greatly reduce memory requirements as well. Without knowing a great deal more about what kind of state is needed or what kind of data (and the frequency of and duration of) these transactions entail it is nigh on impossible to say what system would work best. If you are moving to .Net from VB6 many, many things have changed and this could be a good time to go back to the drawing board and see if any improvements could be made in the design of the software as well as how it is coded. Edited April 3, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mjohnson3091 Posted January 20, 2005 Author Posted January 20, 2005 If a webservice ever 'dies' then it will normally just respaw the worker process and it can start accepting request again, the clients might just have to trap an error and resubmit their data. Not having multiple instances of the app in memory will greatly reduce memory requirements as well. Without knowing a great deal more about what kind of state is needed or what kind of data (and the frequency of and duration of) these transactions entail it is nigh on impossible to say what system would work best. If you are moving to .Net from VB6 many, many things have changed and this could be a good time to go back to the drawing board and see if any improvements could be made in the design of the software as well as how it is coded. Thanks mate, I'll bear that in mind. Looks like it's back to the drawing board then! :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.