hi guys
in this post i will talk about the difference between web service , web API , WCF
so let's go
first why we use this technologies?
if you have any logic and need to make it shared and compatible with any machines and any software you will need to put this logic or methods on the web or shared network and make results as XML or JSON to be compatible with different framework .
so you will need technologies such as web service , web api , WCF to make this
web services :-
used to make your logic code accessible over web and HTTP protocol.
web services use SOAP (Simple Object Access Protocol) that use HTTP + XML
web services return its result as XML (Extensible Markup Language) and can return JSON (JavaScript Object Notation) but common that return XML
web services is action-based model that mean web services contain action not related to specific object or resource for example web service contain method for Add two integer numbers and method for Add two complex numbers and method for multiply and so on all in one web services
commonly using web service in simplex communication (Server to Client ) not in half duplex or full duplex communication
to create Web service for example in . net create web service project and add your methods and decorated it [web method] attribute and to use it add web reference
web service use WSDL (web services Description Language) to describe web service and its functionality
and use UDDI (universal Description ,Discovery and Integration ) to hosting and publishing web services
Web API:-
web API like web services used to put your logic globally and compatible with different framework
But web API use REST API
RESTful API is resource based that mean your logic methods related with resource or object for example make web api that make mathematics operations on integer and complex numbers
you will build two classes one for control integer service operation and second to control complex numbers services operation so RESTful API is resource based
RESTful API use six constraints to create valid REST architectures:-
- Uniform Interface
- Stateless
- Cacheable
- Client -Server
- Layered System
- Code on demand (optional)
Uniform Interface:
that mean must there is separation between structure and implementation of web API
first you create interface and define your abstract methods (define name of method and input and output without any implementation body)
and in implementation process web API controller will implement interface and create all logic
Stateless
mean REST api stateless protocol because it use HTTP protocol that mean server not known any thing about user request after send response . server not store any information about user all needed data will send as parameter to service operation
Cacheable
mean REST api result can be cached to increase performance
Client -Server
mean REST API use client - server model
Layered System
mean REST API has layered application and organized level . service operation not has direct access on database but call data access layer to use database and any business logic must implemented in business logic layer
Code on demand
this option constraint that mean if you need services operation (method) return logic or code , you can return it as javascript code
finally web API can represent result as XML or JSON
WCF:
it is Microsoft technology to build logic on web like web service and web API
but WCF is more larger and detailed . WCF not depend on only HTTP Protocol but it can use other different network protocol like TCP , MSMQ and more
WCF used to build any communication types Simple , half duplex , full duplex
to create WCF :
create data contract to define result data and its members to serialization / deserialization
and make them by decorate interface [DataContract] attribute and its memeber [DataMember]
create service contract to define services functionality structure
and decorate interface [ServiceContract] and its methods [OperationContract]
implement service contract interface and define method logic in service class
define end point (ABC)
- A => Address of service
- B => Binding Protocol
- C =>Contract
No comments:
Post a Comment