Client Access WebService

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

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.