•函数调用完整签名
–Invoke(arg1, …, argN, onSucceeded, onFailed, userContext)
•回调函数完整签名
–onSucceeded(result, userContext, methodName)
–onFailed(error, userContext, methodName)
•WebService级别默认属性
–timeout
–defaultUserContext
–defaultSucceededCallback
–defaultFailedCallback
aspx
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="ErrorHandling.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" value="getDivision" onclick="getDivision(5, 0)" />
<input type="button" value="timeout" onclick="timeout()" />
<script language="javascript" type="text/javascript">
ErrorHandling.set_defaultFailedCallback(failedCallback);
ErrorHandling.set_timeout(2000);
function getDivision(a, b)
{
ErrorHandling.GetDivision(a, b);
}
function timeout()
{
ErrorHandling.Timeout();
}
function failedCallback(error, userContext, methodName)
{
var message = String.format(
"Timeout: {0}\nMessage: {1}\nExceptionType: {2}\nStackTrace: {3}",
error.get_timedOut(),
error.get_message(),
error.get_exceptionType(),
error.get_stackTrace());
alert("Error at " + methodName + "\n\n" + message);
}
</script>
</form>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="ErrorHandling.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" value="getDivision" onclick="getDivision(5, 0)" />
<input type="button" value="timeout" onclick="timeout()" />
<script language="javascript" type="text/javascript">
ErrorHandling.set_defaultFailedCallback(failedCallback);
ErrorHandling.set_timeout(2000);
function getDivision(a, b)
{
ErrorHandling.GetDivision(a, b);
}
function timeout()
{
ErrorHandling.Timeout();
}
function failedCallback(error, userContext, methodName)
{
var message = String.format(
"Timeout: {0}\nMessage: {1}\nExceptionType: {2}\nStackTrace: {3}",
error.get_timedOut(),
error.get_message(),
error.get_exceptionType(),
error.get_stackTrace());
alert("Error at " + methodName + "\n\n" + message);
}
</script>
</form>
cs
protected void Page_Load(object sender, EventArgs e)
{
}
{
}
ErrorHandling.asmx
<%@ WebService Language="C#" Class="ErrorHandling" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Threading;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ErrorHandling : System.Web.Services.WebService
{
[WebMethod]
public int GetDivision(int a, int b)
{
return a / b;
}
[WebMethod]
public int Timeout()
{
Thread.Sleep(5000);
return 0;
}
}
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Threading;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ErrorHandling : System.Web.Services.WebService
{
[WebMethod]
public int GetDivision(int a, int b)
{
return a / b;
}
[WebMethod]
public int Timeout()
{
Thread.Sleep(5000);
return 0;
}
}