1. WebService in CS background Program In
A. Use the namespace and class name to directly call
Example:
WebService Ws = new WebService ();
String S = ws. helloworld ();
B. Call by adding a web reference. First, add a web reference and use a URL to point to WebService,
Specify the Web reference name, which is assumed to be KK;
Example:
KK. WebService n = new KK. WebService ();
String Ss = n. helloworld ();
Ii. WebService JS call method on the front-end page
1. First, use the following method to reference WebService in the foreground:
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
<Services>
<Asp: servicereference Path = "WebService. asmx" inlinescript = "true"/>
</Services>
</ASP: scriptmanager>
2. You can call the SDK through the JS program, for example:
<SCRIPT type = "text/JScript">
Function ()
{
WebService. helloworld (onresult );
}
// Here the onresult is the callback function
Function onresult (result)
{
Alert (result );
}
Function B ()
{
WebService. Add (1, 2, onreturn)
}
Function onreturn (result)
{
Alert (result );
}
// The following 'context' is the context, which can be obtained by returning to the function through reloading;
Function C ()
{
WebService. Div (1, 1, onresultc, onerror, 'context ');
}
Function onresultc (Res, c)
{
Alert (RES );
Alert (C );
}
// Onerror is the callback function used to obtain the exception information. The following describes how to obtain the exception information.
Function onerror (error)
{
VaR A = "";
A = string. format ("Get server exception type: {0} \ t \ n get detailed exception description: {1} \ t \ n get cause exception: {2} \ t \ n gets the stack with an exception on the server.
Trace information: {3} \ t \ n gets a Boolean value, indicating whether the exception is caused by network connection timeout {4 }",
Error. get_exceptiontype (),
Error. get_message (),
Error. get_statuscode (),
Error. get_stacktrace (),
Error. get_timedout ())
Alert ();
}
A ();
B ();
C ();
</SCRIPT>