WebService release method on the server
• Compile a common ASP. NET WebService
• Add custom property tags for the WebService class
-Scriptserviceattribute
• WebService Release Method
-The access level is public.
-Use webmethodattribute to mark
• Introduce the asmx file to the scriptmanager (proxy) on the page
Client Access WebService
• [Namespaces.] classname. methodname
• Input parameters in sequence
• Pass in a method as the callback function after success
• The callback function is called even if no return value is returned.
Client Access to WebService Basics
Aspx < Form ID = " Form1 " Runat = " Server " >
< ASP: scriptmanager ID = " Scriptmanager1 " Runat = " Server " Scriptmode = " Debug " >
< Services >
< ASP: servicereference path = " Webservicefoundation. asmx " Inlinescript = " True " />
</ Services >
</ ASP: scriptmanager >
< Input type = " Button " Value = " Get random " Onclick = " Getrandom () " />
< Input type = " Button " Value = " Get range random " Onclick = " Getrandom (1, 50,100) " />
< Script Language = " Javascript " Type = " Text/JavaScript " >
Function getrandom (minvalue, maxvalue)
{
If (Arguments. Length ! = 2 )
{
Sample. webservicefoundation. getrandom (getrandomsucceeded );
}
Else
{
Sample. webservicefoundation. getrangerandom (minvalue, maxvalue, getrandomsucceeded );
}
}
Function getrandomsucceeded (result)
{
Alert (result );
}
</ Script >
</ Form >
CSProtected VoidPage_load (ObjectSender, eventargs E)
{
}
Webservicefoundation. asmx<%@ WebService Language="C #"Class="Sample. webservicefoundation" %>
UsingSystem;
UsingSystem. Web;
UsingSystem. Web. Services;
UsingSystem. Web. Services. Protocols;
UsingSystem. Web. Script. Services;
Namespace Sample
{
[WebService (namespace = " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
[Scriptservice]
Public Class Webservicefoundation: system. Web. Services. WebService
{
[Webmethod]
Public Int Getrandom ()
{
Return New Random (datetime. Now. millisecond). Next ();
}
[Webmethod]
Public IntGetrangerandom (IntMinvalue,IntMaxvalue)
{
Return NewRandom (datetime. Now. millisecond). Next (minvalue, maxvalue );
}
}
}