两种情况:
1. WebService中返回自定义类
2. WebService中的参数是自定义类
简单示例:
WebService代码:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService] //这个要右键“添加引用”:System.Web.Extensions
public class Service : System.Web.Services.WebService
{
public Service () {}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
//这个服务返回一个自定义类
[XmlInclude(typeof(Student))] //用于返回自定义类的序列化
[WebMethod]
public Student SetStudent(string pID, string pName, int pAge)
{
Student myStudent = new Student(pID,pName,pAge);
return myStudent;
}
//这个服务传入一个自定义类参数,返回一个string