There are two ways by which we can consume a web service one is using ‘Services’ tag and the other is by using properties defined in Ajax components like ‘ServicePath’ , ‘ServiceMethod’ and ‘ServiceURL’.
Figure 18.17 :- Referencing web service
If you make ‘InLineProxy’ property to true you should see the below code snippet when do a view source on the browser.
var WebService=new function()
this.appPath = "http://localhost:4430/AtlasWebSite3/";
Let’s look at the second method using ‘
ServiceMethod’ and ‘
ServicePath’. Atlas components which display data to the end user have certain properties which help you in consuming web service and invoke methods on those web services. So let’s demonstrate a simple sample using the ‘
AutoCompleteExtender’ component. ‘
AutoCompleteExtender’ is used to enhance a text box with auto complete functionalities. Below is a text box which is enhanced with the ‘
Figure 18.18: - Textbox with AutoComplete feature
So let’s first define the web service. Below is a simple web service which exposes a word list for implementing the auto complete feature in the text box.
Figure 18.19: - Web Service for auto complete functionality
Once we have defined the web service we need to drag and drop the ‘AutoCompleteExtender’ on the ASPX page.
Figure 18.20: - Drag and drop AutoCompleteExtender
Now if you do a view source you should see the below code in HTML. We have numbered the code to highlight the important section.
- 1 -> This is the ‘autocompleteextender’ tag which is dragged and dropped from the tool box.
- 2 -> We need to specify the web service URL and the method of the web service. These can be defined using ‘ServiceMethod’ and ‘ServicePath’ properties.
- 3 -> We also need to define which text box control the ‘AutoCompleteExtender’ will be point to. This is achieved by using the ‘TargetControlId’ property.
That’s it, run the program and see text box performing the auto extender functionality.
Figure 18.21: - ServiceMethod and ServicePath
The ‘ServiceURL’ property can be found in DataSource control.
Asked In: Many Interviews |