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.