• 复杂数据类型使用基础


    复杂数据类型使用基础
    •公有属性或公有Field会被释放和接受
    •容器对象
    –实现IList接口的对象
    –实现IDictionary接口的对象
    •Key必须是String

    aspx
        <form id="form1" runat="server">
            
    <asp:ScriptManager ID="ScriptManager1" runat="server">
                
    <Services>
                    
    <asp:ServiceReference Path="ComplexType.asmx" />
                
    </Services>
            
    </asp:ScriptManager>
            
            
    <input type="button" value="Double Salary" onclick="doubleSalary()" />
            
    <input type="button" value="Reverse" onclick="reverse([1, 2, 3, 4, 5])" />
            
    <input type="button" value="Get Employees" onclick="getEmployees()" />
            
            
    <script language="javascript" type="text/javascript">
                function doubleSalary()
                {
                    var employee 
    = new Object();
                    employee.FirstName 
    = "Jeffrey";
                    employee.LastName 
    = "Zhao";
                    employee.Salary 
    = 1000;
                    
                    ComplexType.DoubleSalary(employee, doubleSalarySucceeded);
                }
                
                function doubleSalarySucceeded(result)
                {
                    var message 
    = String.format(
                        
    "First Name: {0}\nLast Name: {1}\nFull Name: {2}\nSalary: {3}",
                        result.FirstName,
                        result.LastName,
                        result.FullName,
                        result.Salary);
                        
                    alert(message);
                }
                
                function reverse(array)
                {
                    ComplexType.Reverse(array, function(result){alert(result);});
                }
                
                function getEmployees()
                {
                    ComplexType.GetEmployees(getEmployeesSucceeded);
                }
                
                function getEmployeesSucceeded(result)
                {
                    
    for (var name in result)
                    {
                        alert(name 
    + "" + result[name].Salary)
                    }
                }
                
            
    </script>
        
    </form>

    cs
        protected void Page_Load(object sender, EventArgs e)
        {

        }

    ComplexType.asmx
    <%@ WebService Language="C#" Class="ComplexType" %>

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Collections.Generic;

    [WebService(Namespace 
    = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo 
    = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class ComplexType  : System.Web.Services.WebService {

        [WebMethod]
        
    public Employee DoubleSalary(Employee employee)
        {
            employee.Salary 
    *= 2;
            
    return employee; 
        }

        [WebMethod]
        
    public List<int> Reverse(List<int> list)
        {
            list.Reverse();
            
    return list;
        }

        [WebMethod]
        
    public IDictionary<string, Employee> GetEmployees()
        {
            Dictionary
    <string, Employee> result = new Dictionary<string, Employee>();

            Employee emp1 
    = new Employee();
            emp1.FirstName 
    = "Jeffrey";
            emp1.LastName 
    = "Zhao";
            emp1.Salary 
    = 1000;
            result[emp1.FullName] 
    = emp1;

            Employee emp2 
    = new Employee();
            emp2.FirstName 
    = "Tom";
            emp2.LastName 
    = "Chen";
            emp2.Salary 
    = 2000;
            result[emp2.FullName] 
    = emp2;

            
    return result;
        }
    }


    Employee.cs
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    /// <summary>
    /// Summary description for Employee
    /// </summary>
    public class Employee
    {
        
    public string FirstName;

        
    public string LastName;

        
    public int Salary;

        
    public string FullName
        {
            
    get
            {
                
    return this.FirstName + " " + this.LastName;
            }
        }
    }
  • 相关阅读:
    HDU-4609 3-idiots FFT
    HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)
    HDU-1007 Quoit Design 平面最近点对
    POJ-3714 Raid 平面最近点对
    HDU-4631 Sad Love Story 平面最近点对
    HDU-4630 No Pain No Game 树状数组+离线操作
    HDU-4628 Pieces 搜索 | DP
    HDU-4627 The Unsolvable Problem 简单数学
    HDU-4638 Group 树状数组+离线
    HDU-4635 Strongly connected 强连通,缩点
  • 原文地址:https://www.cnblogs.com/timy/p/1172858.html
Copyright © 2020-2023  润新知