Web Service and Communication:
- A web service is like a reusable function available on a server.
- Think of it this way: when you order something online, you're sending a request to the server, and the response you receive is like the confirmation of your order.
- The difference from regular web browsing (HTTP) is that web services are like specific functions that you request to use. It's like the difference between viewing a webpage (HTTP) and actually making something happen on that webpage (web service).
- For example, consider a weather forecasting web service. If you want to know the weather for a certain location, you send a request, and the service responds with weather data.
- Example of Web Service Communication:
Imagine you have a web service that translates English to French.
You send a request like this:
<translateRequest> <sourceLanguage>English</sourceLanguage> <targetLanguage>French</targetLanguage> <text>Hello, how are you?</text> </translateRequest>
The service processes this and responds with an XML like:
<translateResponse> <translatedText>Bonjour, comment ça va ?</translatedText> </translateResponse>
Advantages of Web Services:
- Reusability: Functions can be used across different applications.
- Interoperability: Web services can work regardless of the programming languages or platforms used.
- Scalability: Multiple clients can simultaneously access a single web service.
Web Service Components:
- XML (eXtensible Markup Language): Contains data and defines which service to call.
- SOAP (Simple Object Access Protocol): A communication protocol that goes beyond regular HTTP. It wraps XML messages for sending and receiving between the client and server. SOAP ensures messages are understood by both sides.
- WSDL (Web Services Description Language): Describes what's inside a web service, its operations, input, output, etc.
- UDDI (Universal Description, Discovery, and Integration): A sort of dictionary that keeps track of all available web services. It helps clients find and understand services.
SOAP Message Format and Example:
- A SOAP message is like a letter with specific parts: the envelope and the content.
- The envelope contains information like the sender, receiver, and the action needed.
- The content holds the actual data being sent.
Example of SOAP Message:
- Consider a simple calculator service.
- The request envelope might look like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <AddNumbersRequest> <Number1>5</Number1> <Number2>10</Number2> </AddNumbersRequest> </soap:Body> </soap:Envelope>
- The response envelope:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Body> <AddNumbersResponse> <Result>15</Result> </AddNumbersResponse> </soap:Body> </soap:Envelope>
Example of WSDL:
- Imagine you have a currency converter service.
- The WSDL might define operations like
ConvertCurrency
with inputs and outputs. Here's a simple example of a WSDL definition for a web service that converts currency from Indian Rupees (INR) to US Dollars (USD):
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.com/currency-converter" targetNamespace="http://www.example.com/currency-converter"> <wsdl:message name="ConvertCurrencyRequest"> <wsdl:part name="amount" type="xs:double"/> </wsdl:message> <wsdl:message name="ConvertCurrencyResponse"> <wsdl:part name="convertedAmount" type="xs:double"/> </wsdl:message> <wsdl:portType name="CurrencyConverterPortType"> <wsdl:operation name="ConvertCurrency"> <wsdl:input message="tns:ConvertCurrencyRequest"/> <wsdl:output message="tns:ConvertCurrencyResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CurrencyConverterBinding" type="tns:CurrencyConverterPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="ConvertCurrency"> <soap:operation soapAction="http://www.example.com/currency-converter/ConvertCurrency"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="CurrencyConverterService"> <wsdl:port name="CurrencyConverterPort" binding="tns:CurrencyConverterBinding"> <soap:address location="http://www.example.com/currency-converter"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Explanation:
- This WSDL defines a currency converter web service.
- It has a single operation,
ConvertCurrency
, which takes anamount
of typexs:double
(numeric value) as input. - The output of the operation is the
convertedAmount
of typexs:double
. - The binding specifies the use of SOAP for communication over HTTP.
- The
soap:address
element within thewsdl:service
defines the location of the service. WSDL - Web Services Description Language:
WSDL is like a detailed instruction manual for web services. It describes how you connect to a specific method or function that needs to be called on a remote server. It specifies important information like the data types, data elements, and the operations that can be performed using the service. WSDL also provides the necessary information about the URL where the service can be accessed.
- Type: Defines the data types used in messages. For example,
xs:double
represents a numeric value. - Message: Describes the structure of input and output messages for operations.
- Port Type: Defines a set of operations that can be performed. It's like a contract listing what's available.
- Binding: Describes the communication protocol and message format. It tells you how to communicate with the service. It's like deciding whether to use phone calls or emails to talk.
- Service: The actual implementation of the service, with a specific address (URL).
SOAP vs. WSDL:
- SOAP (Simple Object Access Protocol): It's like the language that messages are written in. It wraps around your data and ensures that it's understood by both the sender and receiver. It's the way information is packaged for delivery.
- WSDL (Web Services Description Language): It's like the blueprint of the service. It tells you what methods are available, what data types they accept, and how to communicate with them.
UDDI - Universal Description, Discovery, and Integration:
Imagine you're in a big city, looking for a specific shop. UDDI is like a directory for services. It's a repository or dictionary where all the services are listed. It's a way to discover what services are available and how you can interact with them.
- Service Requestor: This is you, the client, who wants to use a service.
- Service Provider: This is the entity that hosts the service and provides the functionality.
- Service Broker (UDDI): UDDI is the middleman. It's like the Yellow Pages for services. It helps you find the right service provider.
Example Flow with Client, Server, and UDDI:
- You (Service Requestor) want to use a currency conversion service.
- You don't know where to find it, so you turn to UDDI (Service Broker).
- UDDI provides you with a list of available currency conversion services and their WSDLs.
- Armed with the WSDL, you now know how to communicate with the chosen service provider.
- You send a SOAP request (using the structure from the WSDL) to the service provider (Server).
- The service provider processes your request and sends back a SOAP response.
This whole process is like finding a specific shop in a city using a directory, then understanding the shop's offerings through a detailed manual, and finally interacting with the shopkeeper using a specific language.
Remember, UDDI helps you find the service, WSDL tells you how to talk to it, and SOAP ensures the communication is clear and understood. It's like discovering, understanding, and conversing in the world of web services.
- Type: Defines the data types used in messages. For example,
Assuming you have a Calculator service with the following WSDL:
CalculatorService.wsdl:
xml<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.example.com/calculator"
targetNamespace="http://www.example.com/calculator">
<!-- Define Types and Messages -->
<wsdl:portType name="CalculatorPortType">
<wsdl:operation name="add">
<wsdl:input message="tns:AddRequest"/>
<wsdl:output message="tns:AddResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CalculatorBinding" type="tns:CalculatorPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<soap:operation soapAction="http://www.example.com/calculator/add"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CalculatorService">
<wsdl:port name="CalculatorPort" binding="tns:CalculatorBinding">
<soap:address location="http://www.example.com/calculator"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Now, let's say you want to use the "add" feature of the Calculator service. Here's how you might do it using SOAP:
SOAP Request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns="http://www.example.com/calculator">
<soap:Body>
<tns:add>
<tns:num1>5</tns:num1>
<tns:num2>10</tns:num2>
</tns:add>
</soap:Body>
</soap:Envelope>
In this example:
- The WSDL (
CalculatorService.wsdl
) provides the structure of the service and its operations. - You access the "add" operation through the "CalculatorPort" defined in the WSDL.
- The SOAP request is created with the necessary data (
num1
andnum2
representing the numbers you want to add).
When you send this SOAP request to the URL where the Calculator service is hosted (http://www.example.com/calculator
), the service will process the request and send back a response.
Remember, the WSDL guides you on how to structure your request, and SOAP ensures that your request and the service's response are properly wrapped for communication.
Great I particularly appreciate the way you've broken down complex concepts into simple, easy-to-understand terms. software development in chennai
ReplyDelete