03.Web Service - SOAP
SOAP - Simple Object Access Protocol
This is the GitHub URL of developed project for soap API.
https://github.com/LahiruPriyankara/soapOne
01.Introduction
SOAP
Soap is a xml format that is used to encored and decoded
different massages. When we think about a soap web service it is transfer as
soap massage over the network.
WSDL - Web service Description
Language
Web service descripting language. It describe about
web service in a XML format which every language can understand. Web service එක කොහෙද තියෙන්නේ, end point එකේ
method මොනාද, arguments මොනාද, return
type මොනාදවගේ විස්තර.
UDDI
webservice
එක පිළිබද detail ගන්න පුළුවන් directory තමා UDDI – universal description
discovery interface කියන්නේ.(JNDI ? ).It is a directory where any publisher can
publish their web services and customer can query this directory and get access
all services.
02. SEI – Service Endpoint
Interface
SEI
SEI is an interface to service end point interface. This
provide a way to the client application in respective to the technology to call
the webservice. Depending on the technology we can get service end point
interface. Assume that there is a web service all A. To call it from the java
application, we have java service interface and C# have C# service end point interface.
(Out of the WSDL , can generate SEI.)
client සිට webservice කට හෝ webservice සිට data transfer වන විට එකට language neutral format එකක් බාවිතා කරලා තමා data transfer වෙන්නේ කියන එක සාකච්චා කළා. Sender සහ receiver දෙන්නටම තේරුම් ගන්න පුළුවන් protocol වන XML protocol එකෙන්. මේ XML protocol එකතමා SOAP - simple object access protocol. SOAP (Simple Object Access Protocol) is a messaging protocol that allows programs that run on disparate operating systems (such as Windows and Linux) to communicate using Hypertext Transfer Protocol (HTTP) and its Extensible Markup Language (XML).
SEI-service endpoint interface මගින් java
wage class , xml(soap massage) විදිහට convert කරනවා.it is an interface to the service endpoint that provide
a way to client application with respect to the technology(language) to call the
web service.
It is a language, protocol, XML format that is used to
encored and decoded difference massages.
--------------------------------------------------------------------------
Normally java interface එකක් යනු
මොකද්ද බලමු,
Interface එකක් ලියලා එක class
වලට implement කරලා implementation
එක ලියනවා.ඉතින් interface එක මගින්
කරන්නේ client හා implementation එක අතර අතුරු මුහුනතක් (Interface එකක් ලෙස)
ලෙස ක්රියාකර client ට implementation එක access කරන්න හැකියාව ලබාදීමයි . මෙහිදී interface
එක කියනවා implementation එකේ තියන method
මොනාද ,ඒවාට අවශ්ය වෙන parameters මොනාද සහ ඒවා මොන data type වල
parameters ද , output එක මොනාද
සහ ඒවගේ data type එක මොකද්ද wage දේවල්.
public interface BillerMng {
public Cost getCost(int cost, Biller
biller);
}
ඉහත example එක
බලන්න. එහිදී input වෙන්නේ (int cost,
Biller biller ) වන අතර Biller object එක (එනම් data type එක ) project එක තුලද පවතින්න ඕනේ.ඒ වගේම Cost object එකක් return අතර එයට
project එක තුලම
පැවතිය යුතුය.මෙම project එක තුලදී මෙම interface එක thorough implementation
එක access කරන්න නම් පහත දේවල් අවශ්ය වෙනවා.Interface එක කොහෙද තියෙන්නේ හෙවත් package එක ,Interface name එක ,input parameters මොනද සහ
ඒවගේ data type එක
මොකද්ද,output එක
මොකද්ද සහ ඒවගේ data type එක මොකද්ද වගේ දේවල් .
දැන් හිතමු මෙම implementation එක තියෙන්නේ වෙනම project එකක සහ interface එක through implementation එක access කරන්නේ වෙනම project එකක සිට කියලා.
මෙහිදී project one එක තුල පහත දේවල් ඕනේ වෙනවා.Project
2 එකේ ඇති endpoint
එකේ location
එක (Url එක ),endpoint එකේ name එක, Cost සහ Biller
class දෙක වගේ පිට ඉදන් access
කරන්න අවශ්ය වෙන සෑම දෙයක්ම තිබෙන්නට ඕනේ.මෙහිදී එන problem
එකක් තමා impl
එක java
වලින් develop
කර ඇති අතර,
access කරන්න try
කරන්නේ C#
වලින් ලියලා
තියන project එකක සිටනම්,
java වල interface
එක C# වල use කරලා
හරියන්නේ නෑ.එකට C# interface එකක්
තමා අවශ්ය වෙන්නේ.ඉතින් වෙන language
එකක සිට access කලත්
ඒක ඒ
වගේම තමා.එම නිසා මෙම interface එක language
independent වන language
එකකින් (XML
OR JSON wage) හදලා තිබ්බනම් වැඩේ ලේසි මොකද ඒක ඕනෑම language
එකක් සමග වැඩ කරන නිසා.
ඉතින් web service වලදීත්
මේ ටිකමයි වෙන්නේ.Soap web service වලදී
වෙන්නේ මෙහෙමයි, project 2 එක තුල පවතින්නේ develop කර ඇති web service එක වන අතර මෙම web service එක පිට project වල සිට access කරන්න හැකි වන ලෙස XML වලින් interface එකක් generate කරගෙනු ලබයි(මෙය web service එක deploy කරන glassfish වැනි app server එකෙන් generate කරවා ගත හැක).මෙය WSDL නම් වේ.මෙම WSDL එක තුල service එක access වෙන්නට
අවශ්ය වන සියලුම දේවල් අඩංගු වේ .එනම් ,
1. කොහෙද service එක තියෙන්නේ (URL එක) – Address එක.
2. කොහොමද එක access කරගන්නේ-Address එකට
යන්නේ කොහොමද කියන එක.Bike එකේද ,Train එකේද ,Car එකේද වගේ.මොකද bike එක යන පාරේ train යන්න බෑ ,bike එක යන පාරේ car යන්න බෑ වගේ වෙන්න පුලුඑවන් නිසා .
3. මොකද්ද endpoint එකේ name එක - meet වෙන්න ඕනේ කෙනාගේ නම.
4. Method මොනාද – කරගන්න
ඕනේ දේවල් මොනවද.
5. Input මොනාද සහ ඒවගේ type
මොනවද - සල්ලිද දෙන්න ඕනේ නට්ටන් වෙන මොනා හරිද දෙන්න
ඕනේ.සල්ලි නම් දෙන්නේ ඒ rupees ද නැත්තන් dollarsවලින්ද වගේ ඒවා.
6. Output මොනාදසහ ඒවගේ type
මොනවද -අපිට දෙන්නේ මොනවද, සල්ලි නම්
අපිට දෙන්නේ එය දෙන්නේ rupees ද නැත්තන් dollars වලින්ද.
ඉතින් මෙම
Details තියෙන WSDL
එක C# project එකකට integrate
කරලා C# වලට අදාලව class ටික generate කර ගත හැකි වන අතර මෙම class හරහා service එක access කරගන්න පුළුවන්.හැබැයි service
endpoint එකට අදාලව
හැදෙන්න ඕනේ ඔක්කොම ඒවා හැදෙනවා.සමහරවිට අපි use කරන්නේ එක method එකක්
වෙන්නත් පුළුවන්.එත් ඔක්කොම හැදෙන
නිසා එක අනවශ්ය දෙයක් වෙනවා.එක SOAP
වල disadvantage
එකක් වෙනවා .Rest
වල මේ අවුල වෙන්නේ
නෑ.තවද input and output වල data
type වලට අදාල class
ටික හැදෙනවා
[ Cost getCost(int cost, Biller biller); හි Cost class එක Biller class එක] .නමුත් මෙම class
ටිකත් language
independent ලෙස use
කරන්න පුළුවන් නම්
එම class ද generate කිරීම අනවශ්ය වෙනවා.මේක තමා REST service වලදී වෙන්නේ .මෙහිදී එම class වලින් හදන
object data, JSON ලෙස pass
කරනවා (JSON is
also language independent).Service එකෙන් එන output
ද JSON ලෙස client වෙත pass වෙනවා .ඉතින් මෙසේ class
ටික හැදීම SOAP
වල disadvantage
එකක් වෙනවා.තවද WSDL
එක තුලදී service endpoint method input වලට අදාලව validation
ලියන්න පුළුවන්
අතර ,validation fail නම් service එක call වෙන්න් නැ (මෙය Security
advantage එකක් ).එනම්
අපි හිතමු input එක ලෙස 10 ට අඩු number
එකක් යවන්න ඕනේ
කියලා.එක WSDL එක තුල Configure
කරන්න පුළුවන් 10 ට අඩු number විතරක් server එකට
යවන්න කියලා.නමුත් Rest වලදී නම්
වෙන්නේ server එකට ගියාම ඒ number එක 10ට අඩුද බලන එක
.එක Soap එකත් එක්ක බැලුවම අවුල් තත්වයක්.ඉතින්
මෙය Rest වලට වඩා SOAP වල තියන Security Advance එකක් කියලා කියන්න
පුළුවන්.
SOAP - web Service එක access කරන්න full interface
එකක් දෙනවා.ඒවා use
කරලා XML SOAP
data ලෙස data
communicate වෙනවා.
REST - URL එක ,කොහොමද service එක access කරන්නේ කියලා විතරක්
දෙන අතර input සහ output
JSON වලින් communicate
වෙනවා.
In summary,
Web service වලදී service එක සහ client අතර interface එකක් තිබෙන අතර එම interface එක හරහා client
හා sever එක connect කර ගනී.මෙම interface එක WSDL එක වේ.Web service implement එක access කරන්න ඕනේ නම් එක කරන්නේ මෙම
WSDL එක හරහා වේ(It describes what are the input type,
arguments return types so on.).
WSDL එකේ තමා තියෙන්නේ service endpoint
එක කොහෙද තියෙන්නේ (URL), service endpoint එක මොකද්ද (Name), එකේ තියන method මොනාවද, ඒවාට pass කරන්න ඕනේ මොන type එකේ parameters
ද, return වන data මොනද, and return වෙන්නේ මොන type එකේ data ද වගේ දේවල්.
ඉතින් web
service implantation එක වෙනස් කරත් මේවා වෙනස් නොවන්නේ නම් client
ට එය problem එකක්
වෙන්නේ නෑ.එනම් WSDL එක lock
කරලා තියාගෙන(WSDL එක වෙනස් නොවේ) web service එකේ implantation
එක වෙනස් කරන්න පුළුවන් සහ එක client ට
බලපාන්නේ නැ.
කොච්චර users ලා එම web service එක access ප්රශ්නයක් වෙන්නේ නෑ.මොකද WSDL එක වෙනස් නොවන නිසා (freely can be changed implementation
class).
Normally program වලදී,
Interface හා interface implantationඑක සැලකුවාම normally කරන්නේ interface
එක මුලින් ලියලා implementation එක පසුව
ලිවීමයි.මෙහිදී ඇති වාසි නම් සරලව අපේ idea එක මුලින් interface
එකේ ලියන්න පුළුවන් වීම , interface එක
fixed කරලා තිබ්බම පසු කාලීනව implementation එක වෙනස් කලත් users ලට බලපෑමක් නැති වීම වගේ
ඒවා දකින්න පුළුවන්.තවද implantation එක මුලින් ලියලා පස්සේ interface එක ලියන්නත්
පුළුවන්.
ඉතින් web
service වලදීත් මේක මේ විදිහටම වෙනවා.
web service එක ලියන්න පුළුවන් ආකාර
දෙකක් තබෙන අතර ඒවා නම්,මුලින් service එක ලියලා පස්සේ
එයින් WSDL එක හෙවත් interface එක
generate කරගැනීම(Service first)
සහ මුලින් WSDL එක ලියලා පසුව Service එක generate කීරීම(Contract) කිව හැක.නමුත් දෙවැනි ආකාරයටනම් web
service එක create කරන්නේ නම්
WSDL file එක ගැන idea එකක් අවශ්ය
වෙනවා.මොකද මුලින්ලියන්නේ එක නිසා.
Service first – this is commonly known as ‘code first’
Contract
03. Describing WSDL properties.
portType name="ProductCat" – Name of service end point
<operation name="getCategories"> - Method name
of service end point
<input
– input parameters of service end
point method
<output
– return parameters of service end
point method.
<types>
- types of input parameter and return value of
service end point method
<message name="getCategories"> -service
endpoint එකේඇතිඒඒ
method වලඇති
input setඑකතනි
message එකක්ලෙසසලකනඅතර output එකද
message එකක්ලෙසසලකනුලබයි.එම එක තුලදී ඒ
ඒ method එකේinput හෝ output වල type කරනු ලබයි.()consists of different types
<binding name="ProductCatPortBinding" type="tns:ProductCat">this is basically, how server will accept this
values(Basically binding is how the services accepts the request and give the
response).
Eg;
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> - this service is accept soap request over HTTP.
02 – Port එක.
03 – Endpoint එක.
04- Inputs parameters take as on message.
05- message එකතුලදී input
parameters වලටඅදාල
data වල data types
පිලිබදව configure වන අතර By default මෙම data type වෙනම xml එකක් ලෙස පවතී.නමුත් මෙය වෙනම xml එකක නැතිව message එක තුලම configure කරන්නත් පුළුවන්වේ.වෙනම xml එකක පවතින විට, මෙම xml file එක
කොටසේ
schemaLocation
මගින්
ඇති URL එකෙන් ලබා ගත හැක.
@WebService
@SOAPBinding(style=Style.RPC)
publicclassTestClass {}
ලෙස
යොදා ඇත්නම් මෙය වෙනම xml එකක් ලෙස හැදෙන්නේ නැති අතර,
message එකටම bind වී සැදේ.නමුත් මෙහිදී data validation වැනි දෑකරගත
නොහැක. එම නිසා මෙය default එන්නේ
නැත .default ම එන්නේ,
@WebService
@SOAPBinding(style=Style.DOCUMENT)
publicclassTestClass {}
ලෙස වේ.
With @SOAPBinding(style=Style.DOCUMENT)
With @SOAPBinding(style=Style.RPC)
JAXB – java Architecture for XML Binding
What this does is, this binding the different part of
java object with the different part of the XML Structure and also converting a
peace of XML code to java object.
WSDL and Service Endpoint
Mapping.
WSDL property hierarchy.
04. How to create a SOAP web
Service.
In java
it is very simple process.
1. Create
a web app and create a class in that project.
2. Add @WebService annotation to the class. That’s all.
3. Run the
application
4. Go to
server console log.
5. Then WSDL file can be generated from here.
Sample Code
05. Getting SOAP java files and
class files through CMD.
mkdir soapdir
cd soapdir
wsimport
// using, download all java files
and generate class file. Then delete all java file. Finally only Class files
can be seen in above directory.
wsimport http://lahiru:8080/SoapTestingPrjOne/ProductCatService?wsdl
// using, download all java files
and generate class file and stored those in above directory.
wsimport –keep –s src http://lahiru:8080/SoapTestingPrjOne/ProductCatService?wsdl
06. Calling soap service from a
project (SOAP Client).
Integrate the soap service using
WSDL.
In NetBeans
: right click on the project – new - web service client.
Click finish.
All class files are downloaded
and located in given package.
Then,
මෙහෙදී
ලෙස දෙන
නිසා WSDL එක දෙනු ලබන URL
හරහා නැවත download කරගෙන project
එකේ web
Service එකට අදාල වන generate කරගත් class නැවත refresh කරගනු ලබයි.මෙය web
service එකේ වෙනසක් සිදු කර ඇත්නම් එම update ටික අපේ
project එකට ගැනීමට වැදගත් වේ .
Comments
Post a Comment