Mouse Atlas journey (III): Simple Web Services

Source: Internet
Author: User
Vs2005 is not finished yet. If you are not in a hurry, first translate the Web service in Atlas. Original address:

Http://atlas.asp.net/quickstart/atlas/doc/services/default.aspx
The translation is not very good. Please provide a better translation. Thank you.

Asp.net Atlas allows your webProgramCalling regular web services from a browser (client) brings a rich user experience to web programs, because he does not need to submit the form to the server through PostBack like the traditional method, instead of simply passing the data you need between the browser and the server.

ASP. NET 'Atlas 'provides a basic method for accessing and using web services by accessing JavaScript proxies from web services through a browser.

1. Call simple web services from the ASPX page
1. Add a web service to the site and add the [webmethod] feature to the method you want to call. This is because you can access it from the outside. Below is a simple Web Service:

<% @ WebService Language = "C #" class = "Quickstart. samples. simpleservice" %>Using system; using system. web; using system. collections; using system. web. services; using system. web. services. protocols; namespace Quickstart. samples {[WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] public class simpleservice: system. web. services. webService {[webmethod] Public String echostring (string s) {return s ;}}}

2. Add the following Atlas script on your web page to activate Asp.net atlas on the page. When your page is requested, it will be downloaded.

<Atlas: script id = "script1" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Mozilla "/>
<Atlas: script id = "script2" runat = "server" Path = "~ /Scriptlibrary/atlascompat. js "browser =" Firefox "/>
<Atlas: script id = "script3" runat = "server" Path = "~ /Scriptlibrary/atlasruntime. js "/>

3. Add a javascript Statement on the Web page to point to the Web service with its src attribute. When your page is requested, the. asmx/JS entry will download the Javascript Proxy:

<Script language = "JavaScript" src = "simpleservice. asmx/JS">

4. Now you can call methods in Web services from your page. It is event-driven and has three parameters, the first is the parameter required by the method in the Web Service, and the second parameter is the operation (function) triggered when the data is successfully returned ), the third parameter is the operation (function) triggered by the returned data Timeout ):

Quickstart. samples. simpleservice. echostring (
"Sometext", // Params
Oncomplete, // Complete Event
Ontimeout // timeout event
);

5. You can even directly pass the value of the HTML input control to the method in the Web service.

Quickstart. samples. simpleservice. echostring (
Document. getelementbyid ('inputname'). Value, // Params
Oncomplete, // Complete Event
Ontimeout // timeout event
);

6. In the operation function that successfully obtains data, there is a result parameter, which is the data returned by calling the Web service method. If the response times out, the ontimeout operation is triggered;

Function oncomplete (result)
{
Alert (result );
}

Function ontimeout (result)
{
Alert ("timed out ");
}

Okay. The following is the object of the ASPX page.Code:

<! 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"> 

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.