WebService return type design

Source: Internet
Author: User

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.