Introduction:Web services extend the World Wide Web infrastructure to provide the means for software to connect to other software applications. The Applications access Web services via ubiquitous Web protocols and data formats such as HTTP, XML, and SOAP, without no need getting to worried or confused y about how each Web service is implemented. Web services combine with the best aspects of component-based development and the Web, and are a cornerstone of the Microsoft .NET programming model.

How to create web service project:

1. Select New Web Site option from File Menu in .net IDE.

dhaval Developing Web Application with Web Service

By default it created one method HelloWorld() with string return type.

dhaval1 Developing Web Application with Web Service

All web method I defined in “Service.vb” file.

You can test it by running it (pressing F5).

You will find following result.

dhaval2 Developing Web Application with Web Service

Pressing invoke button will invoke or call HelloWorld() define in web service.

dhaval3 Developing Web Application with Web Service

2. The second step is to publish web service created by you. For that right click on web service project name in solution explorer and select publish web site option . aAs shown in the following window :figure.

dhaval4 Developing Web Application with Web Service

Where “MyWebService” is name of web service to be published (virtual directory).

3. The third step is to create blank web application and link created web service with website project. So, first create a blank website project.

4. Adding Web Reference to web project by right clicking on project name as shown in the following window :.

dhaval5 Developing Web Application with Web Service

5. It Will lead to Add Web Reference dialog box. Where you can find or type url of your web service and browse also.

6. Dialog box gives u three option to search web service

a. Web services in this solution

b. Web services on the local machine

c. Browse UDDI Servers on the local network

The fFirst option is used to search web service in current solution. Second option is used to search web service on your local computer. I do not have any idea about the third option since Third option has no idea for me.Because I never used that one.

So, select second option and that will gives u result of all web service names resides on your local computer.

Select your development ed service from that list.

dhaval6 Developing Web Application with Web Service

It will show a method hello world() which we developed in web service.

dhaval7 Developing Web Application with Web Service

7. Now you can change of web service object while you adding web reference to your project by entering text at right side of upper screen and thenat click on add reference button.

After adding web reference solution explorer will get the has this structure as shown In following dialogue box :picture.

dhaval8 Developing Web Application with Web Service

Now, the main question is how to access that service in your web site. So we move to that step.

8. Now to access web methods create one object of web reference in your project

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim objWebService As New MyWebService.Service

Response.Write(objWebService.HelloWorld)

End Sub

Running project will give output Hello World String return by web service.

Similarly you can define any method in web service and access in your web site.


Developing Web Application with AJAXThe In asp.net 2.0 Microsoft has provided net ajax structure that is known as CallBack feature , in background it uses XMLHttpRequest object for asynchronous data transmission between pages without full page refreshing method.Components of Client Callbacks

· Implement the ICallbackEventHandler interface. You can add this interface declaration to any ASP.NET Web page.

· Include a method that implements the GetCallbackResult() interface. This method will be invoked by the callback, and then it returns a string to the clientCallback function.

· Include a method that implements the RaiseCallbackEvent interface. This method will be invoked by the callback, and process which ever is writing in to it at server side.

Steps to make callback application.

1. Implement ICallbackEventHanlder in page class

public partial class _Default : System.Web.UI.Page , ICallbackEventHandler

2. Creating serverside callback method

string eventArgument = “”;

public void RaiseCallbackEvent(string eventArgument)

{

this.eventArgument = eventArgument;

}

3. Creating server side return result method that returns a result to client side function

public string GetCallbackResult()

{

return “Hello from the Server.\nTime is: ” + DateTime.Now.ToString() +

“\r\nPassed event argument: ” + this.eventArgument;

}

4. Creating client script function and actual implmementation of callback technique.

protected void Page_Load(object sender, EventArgs e)

{

if (!IsCallback)

{

ScriptRef = this.ClientScript.GetCallbackEventReference(

this,

“document.forms[0].btnCallServer.value”,

“OnCallback”,

“this”,

“OnCallback”,

true);

this.btnCallServer.Attributes.Add(”onclick”, ScriptRef);

}

}

5. The Client side code should look like this.

Simple Client Callback
Page loaded on:

You can see that when button is pressed thean callback event is fired and it passes argument as value field of button that is ”Get Server Time” and “GetCallbackResult()” method return time string to “OnCallBack()” method and it displays as alert.In “RaiseCallbackEvent(string eventArgument)” you can perform any serverside functionality and return any result via “eventArgument” variable.So this way you can perform and asynchronous operation using callback functionality and this feature is successfully runs on many browsers that support XMLHttpRequest object.

Author:

By Dhaval Charavda

Dhaval Charavda is working as a Programmer at Semaphore Infotech Pvt. Ltd, India.