What is the logic for WebService methods ?
-
Hallo, Assume that in a Web Service application under .NET in C#, there is a Web Service method that returns an object of type DataTable.. When a client, to this Web service, calls this method, does the resulting object completely (with its all contents) return to the caller platform? Or returns only a reference to an object of DataTable? In other words: Is the actually created object (DataTable) held by WebService apllication? Or is it sent with its whole contents to the client (caller) platform, becoming independent from the connection to WebService anymore??
-
Hallo, Assume that in a Web Service application under .NET in C#, there is a Web Service method that returns an object of type DataTable.. When a client, to this Web service, calls this method, does the resulting object completely (with its all contents) return to the caller platform? Or returns only a reference to an object of DataTable? In other words: Is the actually created object (DataTable) held by WebService apllication? Or is it sent with its whole contents to the client (caller) platform, becoming independent from the connection to WebService anymore??
First, unless you have created your own version of a serializable DataTable, a web method cannot return a DataTable because it is not serializable. However, a DataSet is serializable and thus you can use it to put your data table in it and return it. Now, as I believe, a web service is stateless by nature. You can make it statefull with some extra coding but if you use the model generated by VS, it is stateless. This means that there is no persistence of data and when a method returns, the session expires. So, to answer your question, the client calling the webmethod will get a copy of the DataSet returned and not a reference :) Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
-
First, unless you have created your own version of a serializable DataTable, a web method cannot return a DataTable because it is not serializable. However, a DataSet is serializable and thus you can use it to put your data table in it and return it. Now, as I believe, a web service is stateless by nature. You can make it statefull with some extra coding but if you use the model generated by VS, it is stateless. This means that there is no persistence of data and when a method returns, the session expires. So, to answer your question, the client calling the webmethod will get a copy of the DataSet returned and not a reference :) Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
Thanks for your help Talal. As I am very beginner about WebService, I would like to ask another question upon your remarks: Cannot I use my self-defined type (class) objects in Web Service methods (as a function return type or parameters for functions), if those my-self designed classes are not serializable ?
-
Thanks for your help Talal. As I am very beginner about WebService, I would like to ask another question upon your remarks: Cannot I use my self-defined type (class) objects in Web Service methods (as a function return type or parameters for functions), if those my-self designed classes are not serializable ?
You're welcome. I'm glad I can help. For your classes to be serializable, they need to contain only serializable objects. You can check on MSDN what are the serializable objects. Usually you can have all primitives types like int, string, byte, bool, long, float, etc... as well as arrays of these like int[], byte[], string[] etc...Other types may also be serializable (like DataSet). If you have a class "A" [being used by the web service] that contains some variables that are not serializable, I suggest you move all the serializable variables (those you want to send across the network) to a new class and reference that class in your class "A". Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook