C#源文件:testws.asmx(http://localhost/dxl_green_web/testws.asmx) <%@ WebService Language="c#" Class="dxl_green_web.test" %> using System; using System.Data; using System.IO; using System.Web; using System.Web.Services; namespace dxl_green_web { [Serializable] public class Person { public Person() { } public Person(string name,string gender) { this.Name=name; this.Gender=gender; } public string Name=""; public string Gender=""; } [WebService(Namespace="http://www.dxlschool.com/ws/")] public class test : System.Web.Services.WebService { public test() { } [WebMethod] public string HelloWorld() { return "你好"; } [WebMethod] public string NowD(){ return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); } [WebMethod] public float[] ALtest(int a){ float[] tint=new float[a]; int i=0; while (i<a) { tint[i]=(float)i; ++i; } return tint; } [WebMethod] public string GetPersonTable() { DataTable table=new DataTable("Person"); table.Columns.Add("Name"); table.Columns.Add("Gender"); table.Rows.Add(new string[2]{"Alice","Female"}); table.Rows.Add(new string[2]{"Bob","Male"}); table.Rows.Add(new string[2]{"Chris","Female"}); table.Rows.Add(new string[2]{"Dennis","Male"}); table.Rows.Add(new string[2]{"Eric","Male"}); DataSet dataset=new DataSet("PersonTable"); dataset.Tables.Add(table); System.Text.StringBuilder strbuilder=new System.Text.StringBuilder(); StringWriter writer=new StringWriter(strbuilder); dataset.WriteXml(writer,System.Data.XmlWriteMode.IgnoreSchema); return strbuilder.ToString(); } [WebMethod] public Person[] GetPersons() { Person Alice=new Person("Alice","Female"); Person Bob=new Person("Bob","Male"); Person Chris=new Person("Chris","Female"); Person Dennis=new Person("Dennis","Male"); return new Person[]{Alice,Bob,Chris,Dennis}; } } } |
AS2源文件 import mx.services.*; import mx.services.*; myWebSrvc = new WebService("http://localhost/dxl_green_web/testws.asmx?wsdl"); hl = myWebSrvc.HelloWorld(); hl.onResult = function(result) { trace(result); }; h2 = myWebSrvc.ALtest(100); h2.onResult = function(result) { for (i=0; i<result.length; ++i) { trace(result[i]); } }; h3=myWebSrvc.GetPersons(); h3.onResult=function(result){ trace(result.length); for (i=0; i<result.length; ++i) { trace(result[i]["Name"]); trace(result[i].Gender); } } |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |