Anatomy of a Web Service
1.How Do Web Services Work?
- Because different applications are written in different programming languages, they often cannot communicate with each other. A Web service enables this communication by using a combination of open protocols and standards, chiefly XML, SOAP and WSDL. A Web service uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services. Let's take a look at these three main components of a Web service application.
- The Simple Object Access Protocol or SOAP is a protocol for sending and receiving messages between applications without confronting interoperability issues (interoperability meaning the platform that a Web service is running on becomes irrelevant). Another protocol that has a similar function is HTTP. It is used to access Web pages or to surf the Net. HTTP ensures that you do not have to worry about what kind of Web server -- whether Apache or IIS or any other -- serves you the pages you are viewing or whether the pages you view were created in ASP.NET or HTML.
- Although both messages look the same, they carry out different methods. For instance looking at the above examples you can see that the requesting message uses the
GetBookPrice
method to get the book price. The response is carried out by the getbookpriceResponse
method, which is going to be the message that you as the "requestor" will see. You can also see that the messages are composed using XML.
- How do you know what methods are available in a Web service that you stumble across on the Internet? Well, WSDL takes care of that for you. WSDL is a document that describes a Web service and also tells you how to access and use its methods. Take a look at a sample WSDL file:
The main things to remember about a WSDL file are that it provides you with:
- A description of a Web service
- The methods a Web service uses and the parameters that it takes
- A way to locate Web services
2.SOAP Messaging Programming Models
A SOAP message is sent to an endpoint by way of a point-to-point connection (implemented by the SOAPConnection class).
You use point-to-point connections to establish a request-reply messaging model. The request-reply model is illustrated in Figure 5–6.
3.Writing a SOAP Service
A SOAP service represents the final recipient of a SOAP message and should currently be implemented as a servlet. You can write your own servlet or you can extend the JAXMServlet class, which is furnished in the soap.messaging package for your convenience. This section describes the task of writing a SOAP service based on the JAXMServlet class.
Your servlet must implement either the ReqRespListener or OneWayListener interfaces. The difference between these two is that ReqRespListener requires that you return a reply.
Using either of these interfaces, you must implement a method called onMessage(SOAPMsg). JAXMServlet will call onMessage after receiving a message using the HTTP POST method, which saves you the work of implementing your own doPost() method to convert the incoming message into a SOAP message.
Comments
Post a Comment