Generally, the WebService return value type may be a queried data or a list, or the execution result status (such as Int or bool type ), in addition, if the execution fails, you must also tell the client what causes the failure, whether the parameter is invalid, or the service exception. Of course, you can throw an exception to inform the client. Now I want to introduce a general method that I have summarized. It is very simple, including three core classes:
1. As the base class, the statusdata class is mainly used to return an execution result. The caller only cares about whether the execution is successful or the execution fails:
The result attribute is of the bool type and indicates whether the invocation is successful.
The message attribute is of the string type. If the result is false, the message must indicate the cause of the failure.
2. singledata <t> inherits from the statusdata class and returns service calls for a single piece of data, such as the information returned by a single query or login.
Item is the data that the caller really needs. It can be accessed only when result is true. Otherwise, the cause of failure can be viewed through message.
3. pageddata <t> also inherits the statusdata class and returns the data queried by page.
Pagecount indicates the total number of pages to be queried, total indicates the total number of records, and list indicates the data list returned by the index on the current query page. It can be used only when the result is true, otherwise, view the cause of failure through message. To return this type of call, you must receive at least the parameters including pageindex and the number of records queried per page (pagesize ).
Although it cannot be used as a guideline, you can refer to it at least. Comments are welcome...