1、改變客戶端訪問WebService代理方法名
[WebMethod]
public int GetRandom()
...{
return new Random(DateTime.Now.Millisecond).Next();
}
[WebMethod(MessageName="GetRangeRandom")]
public int GetRandom(int minValue, int maxValue)
...{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
} 如例所示,那麼有兩個參數的GetRandom方法映射到客戶端就是GetRangeRandom方法了。當然,不一定是重載時才能改變方法名,但是在重載時改變方法名才能體現這個標記的意義。2、使用Http的Get方式訪問WebService的方法
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public int GetRangeRandom(int minValue, int maxValue)
...{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
}
3、讓方法返回XML對象
//輸入的XML結構的字符串
<xml>hello</XML>
//被XMLSerializeString處理後輸出的字符串,根元素為string,<>被轉義
<string><xml>hello</XML></string>
4、在WebService方法中使用Session
[WebMethod(EnableSession = true)]
public int AddOne()
HttpSessionState session = HttpContext.Current.Session;
object objValue = session["value"];
int value = objValue == null ? 0 : (int)objValue;
value++;
session["value"] = value;
return value;
}
5、在客戶端調用WebService的安全性
6、不使用WebService代理的對應方法,使用客戶端代理直接調用WebService方法。
function getRandom(minValue, maxValue)
...{
Sys.Net.WebServiceProxy.invoke(
"Services/UseHttpGetService.asmx",
"GetRangeRandom",
true,
...{ "minValue" : minValue,
"maxValue" : maxValue},
onSucceeded,
null,
null,
-1);
} 對應上面的invoke參數說明和例子,對WebService生成的代理方法是如何調用WebService有一定了解