using System;
using System.Web.Services;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Collections;
namespace WebServiceForStock
{
publicclass Person
{
[XmlElement(ElementName="UserName")]
publicstring Name;
[XmlElement(ElementName="UserAge")]
publicint Age;
} publicclass User
{
public Person personInstance ;
[XmlElement(ElementName="UserEmail")]
publicstring Email;
[XmlElement(ElementName="UserPassword")]
publicstring pwd;
} /// CustomizeClass 的摘要说明。
/// 自定义类用XML序列化
/// 可以返回复合的类
///</summary> publicclass CustomizeClass
{
[XmlAttribute()]publicint orderID;
public DateTime orderTime;
[XmlElement("DateTimeRequired")]public DateTime requiredDate;
public DateTime shippedDate;
public ArrayList Details;
[XmlIgnore]publicstring SalesPersonID;
public CustomizeClass()
{
// // TODO: 在此处添加构造函数逻辑
//
} } [XmlRoot(Namespace ="http://www.cnblogs.com/slashout/")]
publicclass Group
{
publicstring GroupName;
// This is for serializing Employee elements. [XmlAnyElement(Name ="Employee")]
public XmlElement[] UnknownEmployees;
// This is for serializing City elements. [XmlAnyElement
(Name ="City",
Namespace ="http://www.cnblogs.com/slashout/")]
public XmlElement[] UnknownCity;
// This one is for all other unknown elements. [XmlAnyElement]
public XmlElement[] UnknownElements;
} }
2.在Service.asmx内进行编辑
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebServiceForStock
{
/// Service1 的摘要说明。
///</summary> publicclass Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的 InitializeComponent();
} private System.Windows.Forms.TextBox textBox1;
//Web 服务设计器所必需的 private IContainer components =null;
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///</summary> privatevoid InitializeComponent()
{
this.textBox1 =new System.Windows.Forms.TextBox();
// // textBox1
// this.textBox1.Location =new System.Drawing.Point(17, 17);
this.textBox1.Name ="textBox1";
this.textBox1.TabIndex =0;
this.textBox1.Text ="textBox1";
} /// 清理所有正在使用的资源。
///</summary> protectedoverridevoid Dispose( bool disposing )
{
if(disposing && components !=null)
{
components.Dispose();
} base.Dispose(disposing);
} #endregion // WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键 [WebMethod]
public User StockService(int UserID)
{
User newUser=new User();
newUser.personInstance=new Person();
newUser.personInstance.Name="Slashout";
newUser.personInstance.Age=25;
newUser.Email="slashout@163.com";
newUser.pwd="test";
return newUser;
} } }