日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

客户端代理的作用

發(fā)布時間:2023/12/1 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 客户端代理的作用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
客戶端代理的作用
?在對象里做了一個標記
–“__type” = “ComplexType.Color”
?服務(wù)器端根據(jù)標記選擇反序列化的目標類型
?可出現(xiàn)“多態(tài)”效果

aspx
????<form?id="form1"?runat="server">
????????
<asp:ScriptManager?ID="ScriptManager1"?runat="server">
????????????
<Services>
????????????????
<asp:ServiceReference?Path="EmployeeService.asmx"?InlineScript="true"?/>
????????????
</Services>
????????
</asp:ScriptManager>
????????
????????
<div>Years:<input?type="text"?id="txtYears"?/></div>
????????
<div>
????????????Status:
????????????
<select?id="comboStatus"?style="width:150px;">
????????????????
<option?value="ComplexType.Intern">Intern</option>
????????????????
<option?value="ComplexType.Vendor">Vendor</option>
????????????????
<option?value="ComplexType.FulltimeEmployee">FTE</option>
????????????
</select>
????????
</div>
????????
????????
<input?type="button"?onclick="calculateSalary()"?value="Calculate!"?/>
????????
????????
<br?/>
????????
<b>Result:</b>
????????
<div?id="result"></div>
????????
????????
<script?language="javascript"?type="text/javascript">
????????????function?calculateSalary()
????????????{
????????????????var?emp?
=?new?Object();
????????????????emp.__type?
=?$get("comboStatus").value;
????????????????
????????????????emp.Years?
=?parseInt($get("txtYears").value,?10);
????????????????
????????????????EmployeeService.CalculateSalary(emp,?onSucceeded);
????????????}
????????????????
????????????function?onSucceeded(result)
????????????{
????????????????$
get("result").innerHTML?=?result;
????????????}
????????
</script>
????
</form> 定義一個emp的Object對象,指定“__type”(何種類型對象,是要轉(zhuǎn)換成相應(yīng)的服務(wù)器端的類型的)的值,兩個下劃線“_”加上“type”

Employees.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;

namespace?ComplexType
{
????
public?abstract?class?Employee
????{
????????
private?int?_Years;
????????
public?int?Years
????????{
????????????
get
????????????{
????????????????
return?this._Years;
????????????}
????????????
set
????????????{
????????????????
this._Years?=?value;
????????????}
????????}

????????
public?string?RealStatus
????????{
????????????
get
????????????{
????????????????
return?this.GetType().Name;
????????????}
????????}

????????
public?abstract?int?CalculateSalary();
????}

????
public?class?Intern?:?Employee
????{
????????
public?override?int?CalculateSalary()
????????{
????????????
return?2000;
????????}
????}

????
public?class?Vendor?:?Employee
????{
????????
public?override?int?CalculateSalary()
????????{
????????????
return?5000?+?1000?*?(Years?-?1);
????????}
????}

????
public?class?FulltimeEmployee?:?Employee
????{
????????
public?override?int?CalculateSalary()
????????{
????????????
return?15000?+?2000?*?(Years?-?1);
????????}
????}
}
這里的Employee類是一個抽象類,它必須被繼承才能過使用

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

using?System;
using?System.Web;
using?System.Collections;
using?System.Web.Services;
using?System.Web.Services.Protocols;
using?System.Web.Script.Services;
using?ComplexType;


///?<summary>
///?Summary?description?for?EmployeeService
///?</summary>
[WebService(Namespace?=?"http://tempuri.org/")]
[WebServiceBinding(ConformsTo?
=?WsiProfiles.BasicProfile1_1)]
[ScriptService]
public?class?EmployeeService?:?System.Web.Services.WebService
{
????[WebMethod]
????[GenerateScriptType(
typeof(Intern))]
????[GenerateScriptType(
typeof(Vendor))]
????[GenerateScriptType(
typeof(FulltimeEmployee))]
????
public?string?CalculateSalary(Employee?employee)
????{
????????
return?"I'm?"?+?employee.RealStatus?+
????????????
",?my?salary?is?"?+?employee.CalculateSalary()?+?".";
????}
}
這里的CalculateSalary方法指定要生成的參數(shù)類型不是Employee而是繼承Employee的類的Intern、Vendor、FulltimeEmployee的子類,是因為Employee是抽象類,在傳入?yún)?shù)時只要傳入Intern、Vendor、FulltimeEmployee中的一種就可以了。

轉(zhuǎn)載于:https://www.cnblogs.com/timy/archive/2008/04/27/1173088.html

總結(jié)

以上是生活随笔為你收集整理的客户端代理的作用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。