C # WebService call method summary

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.