WebService: How to pass multiple parameters and return multiple parameters

Source: Internet
Author: User

WebService:

In the webService project, create two classes with public access,
Request: used to store request parameters;

Public class request
{
Public request ()
{
}
Public string name;
Public string sex;
Public int age;
Public string enable;
}

Response: used to store response parameters;

Public class response
{
Public response ()
{

}
Public string name2;
Public string sex2;
Public int age2;
Public bool marry;
}

How to Use webService:

[WebMethod (Description = "real test")]
Public response change (request re)
{
Response resp = new response ();
Resp. name2 = re. name + "2 ";
Resp. sex2 = re. sex + "2 ";
Resp. age2 = re. age + 2;
Resp. marry = false;
Return resp;
}

This method receives multiple parameters, changes the value, and returns multiple parameters.


To call WebService in a Web project:

Add a webService reference. Assume that the reference name is localhost. The method for using this webService is as follows:
The client does not need to add two classes: request and response.

Localhost. request re = new localhost. request ();
Re. name = "aa ";
Re. sex = "man ";
Re. age = 12;
Re. enable = "true ";
Localhost. Service ser = new localhost. Service ();
Localhost. response res = ser. change (re );
Response. write (res. name2 + "<br>" + res. sex2 + "<br>" + res. age2.ToString () + "<br>" + res. marry. toString ());

When webservice is called, the following error occurs: Access Denied.
Solution: Add "Allow Anonymous access" to the webservice access permission and go to the "Directory Security" tab of the webService attribute.

Related Article

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.