You are on page 1of 9

Web Service

2013

Assignment No:8 Title: WAP for web service creation and cosumption of web service. A web service is a method of communication between two electronic devices over the World Wide Web. A web service is a software function provided at a network address over the web or the cloud, it is a service that is "always on" as in the concept of utility computing. A software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. We can identify two major classes of Web services, REST-compliant Web services, in which the primary purpose of the service is to manipulate XML representations of Web resources using a uniform set of "stateless" operations; and arbitrary Web services, in which the service may expose an arbitrary set of operations. Components of Web Services? The basic Web services platform is XML + HTTP. All the standard Web Services works using following components

SOAP (Simple Object Access Protocol) UDDI (Universal Description, Discovery and Integration) WSDL (Web Services Description Language)

All these components have been discussed in Web Services Architecture section. How Does it Work? You can build a Java-based Web Service on Solaris that is accessible from your Visual Basic program that runs on Windows. You can also use C# to build new Web Services on Windows that can be invoked from your Web application that is based on JavaServer Pages (JSP) and runs on Linux. An Example Consider a simple account-management and order -processing system. The accounting personnel use a client application built with Visual Basic or JSP to create new accounts and enter new customer orders. The processing logic for this system is written in Java and resides on a Solaris machine, which also interacts with a database to store the information. The steps illustrated above are as follows:

Web Service

2013

1. The client program bundles the account registration information into a SOAP message. 2. This SOAP message is sent to the Web Service as the body of an HTTP POST request. 3. The Web Service unpacks the SOAP request and converts it into a command that the application can understand. The application processes the information as required and responds with a new unique account number for that customer. 4. Next, the Web Service packages up the response into another SOAP message, which it sends back to the client program in response to its HTTP request. 5. The client program unpacks the SOAP message to obtain the results of the account registration process. For further details regarding the implementation of Web Services technology, read about the Cape Clear product set and review the product components. A web service is a web-based functionality accessed using the protocols of the web to be used by the web applications. There are three aspects of web service development:

Creating the web service Creating a proxy Consuming the web service

Creating and Consuming of Web Sevice: 1. Click on Web Site Project

2. It will open New Web site Dialog box. Choose ASP.NET web service and give it appropriate name(HelloWorldService) and select your Coding language(C#). Click OK. It will take some time because it will make everything ready for you sir. So, you can start quickly

Web Service

2013

3. What it has created?

Service.cs: is the main file where you can write you code. E.g application logic etc..Calling Data Access layer etc. Service.asmx will expose your service to outer world. 4. Web Method If you will see Service.cs it has one method already written. You can use it as a reference implementation [WebMethod] public string HelloWorld() {

Web Service

2013

return Hello World;

Any method you want to expose you have to declare it by attribute WebMethod.LetS create our new method.So, you can get more into methods.Just copy paste above one and modify it will like this: /// <summary>

/// This method will take argument as a string and show it with greeting /// </summary> ///<param name=name></param> ///<returns></returns> [WebMethod] public string MyHelloWorld(string name) {return Hello World,+name; //Here you can call your Insert,Update,Delete from DAL and write return statement } 1. Build Web Site [CTRL+SHIFT+B]. Thats it we have our service Ready. Lets create one consumer for it. Consumer Our Service is ready. It will take name and return it with Hello World name. I am creating here one Windows application for demo. You can create any client to use it.

Web Service

2013

1. Click on your solution file name Means [Your focus should be on C:\HelloService or your solution name]

2. Select File | Add | New Project

3.It will open Add New Project Dialog Box. Select Windows application and give appropriate name to it. Click OK.

Web Service

2013

4. So now you will have structure as under:

5. Right Click on HelloWorldConsumer project and Click on Add Web Reference- For Adding service reference.

6.It will open Add Web Reference window. Just click on Web Services in this solution. Because we have our service under same solution.

Web Service

2013

7. It will find out service. Just click on it.

8. It will load our methods as shown here: [Web reference name I had changed "localhost" to "HelloWorldClient". So you should also do it. Its good practice]. Click on Add reference button. Which will add our service reference to client.

9. Now your soln structure should look like:

Web Service

2013

10. Click on Form1 and drag some controls so we can test it. So, your form should look like this.

11. Double click on Call Service Button it is Buttton1 for me. For creating its Click event handler code. And it will point it to handler code call your service here and show result in Messagebox as shown here.

Web Service

2013

12. Build solution. And ensure that HelloWorldConsumer-windows application is your startup project. Then run the project [CTRL+F5]

Conclusion:
Thus we have created web service and consumed it.

You might also like