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’.
We can define the web service URL in the ‘Services’ tag using ‘atlas:ServiceReference’ tag. ‘Path’ property defines the web service URL. If we also want to generate javascript proxy we need to set the ‘GenerateProxy’ to true. We have also set one more property i.e. ‘InlineProxy’ property needs to be true so that the proxy code is available to the client javascript.
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.
<script type="text/javascript">
var WebService=new function()
{
this.appPath = "http://localhost:4430/AtlasWebSite3/";
var cm=Sys.Net.ServiceMethod.createProxyMethod;
cm(this,"HelloWorld");
cm(this,"GetWordList");
}
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 ‘AutoComplete
’ feature.
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.