1. WebService calling in cs background program
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 ();
2. WebService JS on the front-end page Call Method
1. First, use the following method to reference Webservice in the foreground:
<Asp: ScriptManager 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 context below 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} get detailed exception description: {1} Get exception cause: {2} Get server exception Stack
Trace information: {3} 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>
---- Example of self-writing ---
Web Service ---:
[WebMethod]
Public string HelloWorld (){
Return "Hello World, wwg ";
}
[WebMethod]
Public int AddWwg (int a, int B)
{
Return a + B;
}
Exe ---
Using CallWebService. localhost; // The namespace is not defined.
Namespace CallWebService
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void button#click (object sender, EventArgs e)
{
Service serviceWwg = new Service ();
Int i1 = Int32.Parse (txt1.Text. ToString ());
Int i2 = Int32.Parse (txt2.Text. ToString ());
Int iResult = serviceWwg. AddWwg (i1, i2 );