Ajax. as one of the mature Ajax platforms. NET platform is developed by Microsoft, so Ajax is used. net client script call. net Development of WebService will be a very simple thing, this is one of the exciting thing.
Next, we will introduce the call process step by step. First, we first use vs2008 to add a WebService, itsCodeAs follows:
- UsingSystem;
- UsingSystem. collections;
- UsingSystem. componentmodel;
- UsingSystem. Data;
- UsingSystem. LINQ;
- UsingSystem. Web;
- UsingSystem. Web. Services;
- UsingSystem. Web. Services. Protocols;
- UsingSystem. xml. LINQ;
- NamespaceWebservice1
- {
- /// <Summary>
- /// Summary of service1
- /// </Summary>
- [WebService (namespace ="Http://tempuri.org /")]
- [Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
- [Toolboxitem (False)]
- // To allow ASP. Net ajax to call this web service from a script, cancel the comments to the downstream.
- [System. Web. Script. Services. scriptservice]
- Public ClassService1: system. Web. Services. WebService
- {
- [Webmethod]
- Public StringHelloworld ()
- {
- Return "Hello World";
- }
- }
- }
Note: add the attribute [system. Web. Script. Services. scriptservice] To the WebService class so that ASP. Net AJAX can call this web service from the script.
Add an Ajax web page and add a reference to WebService to the page. You can write script code to call this WebService. The Code is as follows:
- <% @ PageLanguage="C #" Autoeventwireup="True" Codebehind="Webform1.aspx. cs" Inherits="Webservice1.webform1"%>
- <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <Html Xmlns=Http://www.w3.org/1999/xhtml" >
- <Head Runat="Server">
- <Title>No title page</Title>
- <Script Type="Text/JavaScript">
- Function callmethod ()
- {
- Webservice1.service1. helloworld (succeededcallback );
- }
- Function succeededcallback (RES)
- {
- Alert (RES );
- }
- </Script>
- </Head>
- <Body>
- <Form ID="Form1" Runat="Server">
- <Div>
- <ASP: scriptmanager ID="Scriptmanager1" Runat="Server">
- <Services>
- <ASP: servicereference Path="~ /Service1.asmx" />
- </Services>
- </ASP: scriptmanager>
- </Div>
- <Input ID="Button2" Type="Button" Value="WebService method call" Onclick="Callmethod ()" />
- </Form>
- </Body>
- </Html>
Call methods are almost the same as function calls in C #. They can be called in the form of namespaces, type names, method names, and parameters. in addition, we only need to add a callback method to process the returned results of the call. for basic parameters, you can directly pass them, complex parameters I use the popular JSON technology as the carrier for data transmission. For details about JSON technology, refer to the following article.Article:
JSON Technology and Its Application in JBF for ASP. NET
In addition, the BS part of the ultimate basic business platform is the use of this total JS + webserver technology, a realistic and friendly user interface, you can download from the following URL to the free trial version of the platform.
Http://www.jeez.com.cn/jbf/