WSDL is an XML file which contains following sections.
- service
- binding
- porttype
- message
- type
Service:
The service element in the WSDL defines the name of the
service. Here I used the Employee service. Usually the service name is
constructed from the implementation class + “service”. In our case
implementation class name is EmployeeServiceImpl. The “service” is appended at
the end of the implementation class and the name of our service becomes
EmployeeServiceImplService. It also defines the end-point url or web service
location which is http://localhost:8080/Employee/employee.
The service tag also defines the port name EmployeeServiceImplPort and the
binding tns:EmployeeServiceImplPortBinding.
Binding:
This element defines how the web service accesses the
values. The transport=http://schemas.xmlsoap.org/soap/http
tells the web service is accessed via http. It also specifies we are using the
Document style web service.
Porttype:
Porttype defines the service operations available for the
web service. In the Employee service we have two operations.
- addEmployee
- getEmployees
Consider a normal java method which has one optional return
type and zero or more input arguments.
Similarly our web service operation also has one input and
one output message.
Operation
|
Messages
|
Complex Type
|
Parameter/Return type
|
addEmployee
|
tns:addEmployee
|
addEmployee
|
{empId,empName,{deptId,deptName}}
|
tns:addEmployeeResponse
|
addEmployeeResponse
|
Won’t
return anything
|
|
getEmployees
|
tns:getEmployees
|
getEmployees
|
No
Parameters
|
tns:getEmployeesResponse
|
getEmployeesResponse
|
Employee
array
|
Message:
Is one input and one output message is mandatory? Because
normal java method may not return any output and may not accept any input.
Similarly it may accept more than one input as argument. So how can we define
one input and one output message?
Types:
Types section has the answer for the questions raised in the
messages section. It has attribute schemaLocation which defines the messages in
details. Paste this information in a separate url and you will find a page http://localhost:8080/Employee/employee?xsd=1.
Types referring a namespace http://service.sri.com
which is reversal of the package structure com.sri.service. Each message was defined in terms of primary attribute. For
instance addEmployee method accepts one input argument Employee. Employee has
two primary datatype attributes and one user defined Department. All are defined
in the complexType section in terms of primary attribute.
getEmployees operation may return zero or more employees. To
denote it in the getEmployeeResponse, we have attributes minOccurs=0 and
maxOccurs=unbound.
For the addEmployee operation we need to pass one employee
object. What if we pass the NULL to this method? Because of this, addEmployee
operation defined minOccurs=0. We may pass employee object or we may not pass
anything.
In case of RPC style web service the messages were defined
in WSDL itself instead of a separate schema. Only the user defined data types
were moved to another schema location.
Good one
ReplyDeleteGood one
ReplyDelete