Tuesday, August 19, 2014

SOAP vs REST web services or Difference between SOAP and REST web services



WCF Tutorials – SOAP vs REST web services or Difference between SOAP and REST web services
Before we start differentiate between SOAP vs ReST web services let’s understand what is web service?
According to web definition from WIKI –
“…A web service is a method of communication between two electronic devices over World Wide Web. It is a software function provided at a network address over the web with the service always on as in the concept of utility computing.
In simple words – Web service is a mechanism that provides data as a service/response over the http protocol on request of some other programs.

What is the difference between web site and web service?

Most of the people don’t know the difference between web service and web site. The two looks similar but Web service is different than Web Site.
Web Site is something that presents data on a browser in human readable format. The web sites are meant for easy user navigation. These are basically HTML pages in human readable format when rendered on browser.
Web Service offers service to some other software applications. Upon receiving a request from these software applications it produces a response. This request can also contain some input data for the service to process and depending upon the input data it returns a result.
The result provided by web services are usually meant for software’s so that they can consume it, process it and optionally present well formatted data on the web site. The result produces by web services may or may not be easily readable by the humans. They are meant for software applications only. The popular result formats are XML and JASON. These popular formats are easy to parse and use.
A website may or may not use webservice.
Example of Website: You can go to website https://www.google.co.in/maps and use it to search a map for your address.
Example of Webservice: You have built your own website and on that website you want to show the address of your site visitor. In this case you can call a webservice provided by google maps, pass the desired address to this web service and it will return a map. And now you can show this map on your website.
I hope now you get the clear idea about what is web service and web site. Now let’s take a look at two different types of web services i.e. SOAP and ReST.
ReST and SOAP are the set of specification of information to be used in the implementation of web services. These are messaging protocols used to exchange the information between two programs. The exchange of information is one-way.

What are soap services? / What is soap service?

Simple Object Access Protocol (SOAP) is a XML based structured protocol specification to be used in the implementation of web service. In simple words SOAP web services uses XML as a mechanism for exchanging of information (one way) between the two programs (end points) over any transport layer protocol.
Though for message negotiation and transmission soap is not relies on any particular transport protocol but HTTP (Hyper Text Transfer Protocol) or SMTP (Simple Mail Transfer Protocol) are the two most popular transport protocols used with SOAP. Similarly SOAP is not relying on any particular programming language or operating system as far as they understand XML and SOAP message.
For example, one program running in Windows operating system such as Windows 7 can communicate to another program running in Linux operating system. For this soap will use XML and HTTP.
SOAP message is consist of three parts, i.e. envelope, header and body as shown in below image.
Simple SOAP Architecture
Simple SOAP Architecture

SOAP:envelope

The root element of SOAP message is a SOAP envelope which states what is in the soap message and how to process it. Application looks at the soap:envelope and easily determines what could be the SOAP message. It also helps application to identify the version of the SOAP being used.

SOAP:header

SOAP:Header is an optional element of the soap message. The element from this part contains application specific information. The information should be related to soap message and could be anything like authentication method or payment methods etc.
Though it is an optional element, but if present then it should be the first child element of the soap:envelope.

SOAP:body

SOAP:body is a mandatory element unlike soap header. This part contains all information related to call and response of the web service. Actual soap message goes here.
The format of soap message is as below -

<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<!-- Header elements. -->
</soap:Header>
<soap:Body>
<!-- Body elements. -->
</soap:Body>
</soap:Envelope>

The most important aspect of the SOAP is that without making any changes to the original SOAP message it can tunnel through firewalls and proxies.

What are restful services? / What is restful service?

REST stands for REpresentational State Transfer is a newcomer in its type of family. REST provides very easy access and implementation to a web service that ultimately aims to work best on the web. Restful web services are an architecture style stateless web services mostly used for building client-server applications over HTTP.
In REST, every resource is addressed or accessed by Unique URI (Uniform Resource Identifier) and data and functionality forms a resource. Representation State Transfer defines some set of operations and resources acts according to these operations.
Instead of using XML for request/response, it relies on simple unique URI and that’s why it is also considered as lightweight alternative to SOAP. As it is rely on URI as a resource identifier, the standard CRUD operations of HTTP (GET, PUT, DELETE, POST, HEAD) can be performed on that URI/resource.
SOAP provides the response in XML format only while REST doesn’t have to use XML only. Though XML and HTML formats are often used for REST response, REST can also response in JASON, CSV and RSS formats. There are various options you can choose for the parsing of the REST response. Each of these responses has their own advantages and disadvantages.
“ReST” is lightweight service alternative to most of the mechanism including SAOP and RPC (Remote Procedure Call) but it has no “W3C” recommendations.
In short, ReST is simple, language & platform independent and Standard HTTP based mechanism that can be used through the Firewalls also.
Following are few simple examples of Get & POST upon ReST –
Example 1 :
  1. Request: (URL – http://abc.com/)
    GET /
    Accept: application/json+userdb
  2. Response :
    200 OK
    Content-Type: application/json+userdb
    {
    "version": "1.0",
    "links": [
    {
    "href": "/category",
    "rel": "list",
    "method": "GET"
    },
    {
    "href": "/category",
    "rel": "create",
    "method": "POST"
    }
    ]
    }
Example 2 :
  1. Request : (URL – http://abc.com/category)
    GET /category
    Accept: application/json+userdb
  2. Response :
    200 OK
    Content-Type: application/json+userdb
    {
    "categories": [
    {
    "categoryid": 1,
    "categoryname": "Mobile",
    "links": [
    {
    "href": "/category/1","rel": "self","method": "GET"
    },
    {
    "href": "/category/1",
    "rel": "edit",
    "method": "PUT"
    },
    {
    "href": "/category/1",
    "rel": "delete",
    "method": "DELETE"
    }
    ]
    },
    {
    "categoryid": 2,
    "categoryname": "Tablet",
    "links": [
    {
    "href": "/category/2",
    "rel": "self",
    "method": "GET"
    },
    {
    "href": "/category/2",
    "rel": "edit",
    "method": "PUT"
    },
    {
    "href": "/category/2",
    "rel": "delete",
    "method": "DELETE"
    }
    ]
    }
    ],
    "links": [
    {
    "href": "/category",
    "rel": "create",
    "method": "POST"
    }
    ]
    }
Example 3:
  1. Request : (URL – http://abc.com/category)
    POST /category
    Accept: application/json+userdb
    Content-Type: application/json+userdb
    {
    "categoryname": "Laptops"
    }
  2. Response :
    201 Created
    Content-Type: application/json+userdb
    {
    "category": {
    "categoryid": 3,
    "categoryname": "Laptops",
    "links": [
    {
    "href": "/category/3",
    "rel": "self",
    "method": "GET"
    },
    {
    "href": "/category/3",
    "rel": "edit",
    "method": "PUT"
    },
    {
    "href": "/category/3",
    "rel": "delete",
    "method": "DELETE"
    }
    ]
    },
    "links": {
    "href": "/category",
    "rel": "list",
    "method": "GET"
    }
    }
I hope this articles helps you to understand the difference between SOAP and ReST. If you find this article helpful, then could you please share the article on your social network?
Following articles might be of your interest -

     
  • Informations
  • Web Services
  • Rest web services
  • Windows Xp
  • Windows 7

Difference between Webservice and WCF Service



C#.net : Difference between Webservice and WCF Service
What is the difference between webservice and wcf service? is a very common question in almost every interviews. This is one of the most important topic because programmer should know when to use asp.net web service and when to use wcf service. We should know what is webservice and what is wcf? In other article i have already explained about web service and what is wcf service. The summary of the two is given below.

What is Webservice?

According to web definition from WIKI –
“…A web service is a method of communication between two electronic devices over World Wide Web. It is a software function provided at a network address over the web with the service always on as in the concept of utility computing.”
Web service is a mechanism that provides data as a service/response over the http protocol on request of some other programs.

What is WCF service?

Windows Communication Foundation (WCF) is a often use to develope and deploy network distributed services based on the principles of Service Oriented Architecture (SOA). The fundamental characteristic of WCF is Interoperability. This gives you more manageable approach to create and consume web services.
From the previous posts, we learn to create a WCF service, consume wcf service, self-host wcf service and other various activities.

C#.Net – Web Service Vs WCF service
In this c# tutorial we are going to see the difference between ASP.net web service and WCF service. The table below shows the difference between webservice and wcf. By the end of this article i believe you will completely familier with webservice vs wcf service.

Difference between Webservice and WCF service

Sr. No Features ASP.net Web Service WCF Service
1 File Format/Extension ASP.net web services uses .asmx as a file extension. WCF web service uses .svc as a file extension.
2 Hosting ASP.net Web service can be hosted in IIS. As well as ASP.net WebService can be hosted outside of IIS like ASP.net web service can be hosted in a Windows Service. WCF service is flexible because it can be hosted in IIS, Windows Activation Services(WAS), Managed Windows Services and It also supports Self-Hosting.
3 Transport Protocols/Binding ASP.net Web service supports HTTP & TCP protocols along with custom binding. WCF service supports HTTP, WS-HTTP, TCP, Custom, Named Pipes, MSMQ & P2P(Point to Point) etc.
4 Data Transformation It uses XML serializer for Data Transformation. WCF service uses DataContractSerializer for Data Transformation.
5 Serialization NameSpace System.XML.Serialization System.RunTime.Serialization
6 Supported Operations The supported operations are only One-Way and Request-Response type. The supported operations includes One-Way, Request-Response and Duplex.
7 Encoding It uses following encoding mechanisms -
XML1.0, MTOM (Message Transmission Optimization Mechanism), DIME (Direct Internet Message Encapsulation)
It uses following encoding mechanisms -
XML1.0, MTOM, Binary
8 WebMethods and DataContract Uses WebMethods to translate .Net FW types in to XML.
  • [WebService] attribute has to be added to into the class.
  • [WebMethod] attribute represents the method exposed to the client.
Uses DataContractAttributes and DataMemberAttribute to translate .Net FW types in to XML.
  • [ServiceContract] attribute has to be added to into the class.
  • [OperationContract] attribute represents the method exposed to the client.
9 Messaging Asp.Net web service supports only SOAP(Simple Object Access Protocol) as messaging service. WCF service can send/receive message through any transport protocol message format. However, by default it uses SOAP for communication.
10 Security This is not much secured as compared to WCF. It is less secured to protect data between Server and Client. Certificates can protect the data but it is very complicated to use Certificates. For security, normally we use UserName/Password. As compared to ASP.net web service, WCF services are more secured. WCF does not need IIS to run, it can run as a System Service on the Server, using a command ambient. We can say that WCF is a service and not a Web Service.
11 Performance Performance wise web services are slower than WCF service. WCF services are than WebService. The performance measures in terms of xml serialization.
12 Exception Handling This returns all unhandled exceptions to the client as SOAP faults. WCF does not returns unhandled Exceptions to the client as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to the Client for the purpose of debugging.
13 Limitations
  • Hash Table cannot be serialized.
  • Only public properties/fields can be serialized
  • The DataContractSerializer translate the Hash table into the XML.
  • Public/Private properties/fields can be serialized.
I hope you enjoyed the article that explains the difference between webservice and wcf. If you find this article helpful, then could you please share the article on your social media?
Following articles might be of your interest

Tuesday, May 27, 2014

Oracle simple procedure for insert record

create or replace PROCEDURE                 USP_SAVE_CUSTOMERS
(
  P_CUSTOMERNAME IN VARCHAR2
, P_CONTACTPERSON IN VARCHAR2
, P_PHONE IN VARCHAR2
, P_EMAIL IN VARCHAR2
, P_ADDRESS1 IN VARCHAR2
, P_ADDRESS2 IN VARCHAR2
, P_CITY IN VARCHAR2
, P_STATE IN VARCHAR2
, P_ZIP IN VARCHAR2
, P_DESCRIPTION IN VARCHAR2
, P_ISACTIVE IN NUMBER
, P_CREATEDBY IN NUMBER
)
AS
BEGIN
 INSERT INTO TBL_CUSTOMER
 (
  CUSTOMERNAME,
  CONTACTPERSON,
  PHONE,
  EMAIL,
  ADDRESS1,
  ADDRESS2,
  CITY,
  STATE,
  ZIP,
  DESCRIPTION,
  STATUS,
  CREATEDBY,
  MODIFIEDDATE,
  MODIFIEDBY
 )
  VALUES
  (
  P_CUSTOMERNAME
, P_CONTACTPERSON
, P_PHONE
, P_EMAIL
, P_ADDRESS1
, P_ADDRESS2
, P_CITY
, P_STATE
, P_ZIP
, P_DESCRIPTION
, P_ISACTIVE
,P_CREATEDBY
,(TO_CHAR(SYSDATE))
,P_CREATEDBY
);
COMMIT ;
END USP_SAVE_CUSTOMERS;

Saturday, April 26, 2014

Using row_number() Sql query

create table #t
(
s int
)

create table #p
(
s int
)

insert into #t(s) values(1)
insert into #t(s) values(2)
insert into #p(s) values(3)
insert into #p(s) values(4)

insert into #t(s) values(3)
insert into #t(s) values(4)
insert into #p(s) values(5)
insert into #p(s) values(6)

  select a.s, b.s from
  (select t1.s, ROW_NUMBER() over(order by t1.s) a from #t t1) a

 join

  (select t2.s, ROW_NUMBER() over(order by t2.s) b from #p t2 ) b
  on a.a=b.b

Thursday, April 17, 2014

Tender Search Dynamic Sql Proc

-- =============================================                                                        
-- Author:  Javed khan                                                        
-- Create date: 17/04/2014                                                      
-- Description: for dynamic search of frnchies    
                                                   
-- =============================================    
CREATE procedure [dbo].[lsp_busSearchTenderAdv]      
(      
 @UID bigint,      
 @tenderType smallint,
 @countryId varchar(3),
 @stateId int,

 @ctgryid int,      
 @subctgryid int,      
       
 @amount int,      
 @curncyid int        
)      
as      
begin      
   
declare @qrystr varchar(max)      
     
set @qrystr='select      
(select COUNT (tl.usrid) from tblUsrLike tl where tl.shrtypId=27 and tl.usrShrid=frn.Tid and tl.sts=1) as liked,                
(select tls.sts from tblUsrLike tls where tls.shrtypId=27 and tls.usrShrid=frn.Tid and tls.usrid=frn.usrid) as likedsts,                
(select COUNT(td.usrid) from tblUsrDislike td where td.shrtypId=27 and td.usrShrid=frn.Tid and td.sts=1) as disliked,                
(select tds.sts from tblUsrDislike tds where tds.shrtypId=27 and tds.usrShrid=frn.Tid and tds.usrid=frn.usrid) as dislikedsts,            
             
                         
cmp.compid,cmp.compName,cmp.estblst,cmp.compaddrs,cmp.compcontact,                          
''UserFiles/100/''+convert(varchar,cmp.usrid)+''/CompDealsOffer/''+convert(varchar,cmp.compid)+''.''+right(cmp.imgurl,3)+'''' as compImg,                          
[dbo].[fn_Bussubsubcat](cmp.compid)as subsubctgry,                          
dtl.compctgryid,dc.subctgryname,ctg.ctgname,dtl.compctgryid,cmp.compweb,                          
frn.Tid,frn.Ttitle,tp.typename,frn.Tprice,cntry1.crncyName as currency,convert(varchar(20),frn.Opndate,101) as Opendate      
,convert(varchar(20),frn.closedate,101) as closedate,      
cntry.cntryname,frn.cntryid,sts.lName as stateName,frn.stateid      
,(case when frn.Tdoc is null then ''No file'' else frn.Tdoc end) as agrmnt,(case when frn.Tdoc is null then ''no file'' else                          
''UserFiles/100/''+convert(varchar,frn.usrid)+''/TenderDoc/''+convert(varchar,frn.Tid)+''.''+[dbo].[getFileEXT](frn.Tdoc)+''''                        
 end) as TenderFile,      
 frn.TandC,frn.Tdec,
 vw.name,vw.cityname,vw.image as usrimg,frn.usrid      
from tbltender frn        
inner join tbltndrType tp on tp.typeid=frn.Ttype                          
left join tblcurrency cntry1 on frn.curncyid=cntry1.crncyid                        
inner join tblbusofferComp cmp on frn.cmpnyid=cmp.compid        
inner join tblcountry cntry on cntry.cntrycode=frn.cntryid      
inner join  tblAddrsLevel1 sts on sts.id=frn.stateid                      
inner join (select distinct compid, compsubctgryid,compctgryid from tblbusoffercompDtl) dtl on cmp.compid=dtl.compid                          
inner join tblusrprflctgry ctg on dtl.compctgryid=ctg.usrprflcatgryid                            
inner join tblUsrPrflSubCtgry dc on dtl.compsubctgryid=dc.usrprflsubctgryid
inner join vwfrndlistfld vw on frn.usrid=vw.usrid                            
where frn.isDel=0'      
if(@tenderType!='')      
set @qrystr=@qrystr+' and frn.Ttype='+cast(@tenderType as varchar(150))      
       
if(@countryId!='')      
set @qrystr=@qrystr+' and frn.cntryid='+cast(@countryId as varchar(150))      
       
if(@stateId!='')      
set @qrystr=@qrystr+' and frn.stateid='+cast(@stateId as varchar(150))      
if(@ctgryid!='')      
set @qrystr=@qrystr+' and cmpdtl.compctgryid='+cast(@ctgryid as varchar(150))
if(@subctgryid!='')      
set @qrystr=@qrystr+' and cmpdtl.compsubctgryid='+cast(@subctgryid as varchar(150))
       
if(@amount!='')      
set @qrystr=@qrystr+' and frn.Tprice='+cast(@amount as varchar(150))
if(@curncyid!='')      
set @qrystr=@qrystr+' and frn.curncyid='+cast(@curncyid as varchar(150))      
     
set @qrystr=@qrystr+' order by frn.cdate desc'      
     
exec (@qrystr)      
end 

Sunday, April 13, 2014

show visiting card for evisiting card

 =============================================                      
                                                           
-- Create date: 09/04/2013                                      
-- Description: Show visiting card for multiple profile                                      
-- =============================================                                      
CREATE proc [dbo].[lsp_MultPrflVisitingcard]                                              
@usrid bigint                                             
as                                                 
                                      
begin                                  
  select  top 100   
 (select COUNT(*) from tblusrNoOfViews where mdlid=21 and shrid=p.usrprflid) as totalview,        
(select count(tmp.usrid) from       
(select distinct usrid from tblUsrShrNtwrk where shrType=21 and shrid=p.usrprflId      
 union      
select distinct usrid from tblUsrShrGrpNtwrk where shrType=21 and shrid=p.usrprflId) as tmp) as shared,      
(select ReportTypStId from tblUsrReport where  mdlid=21 and ShrId=p.usrprflId and usrid=@usrid) as reportsts,            
(select count(*) from tblusrrating where  mdlid=21 and ShrId=p.usrprflId) as raters,            
(select count(*) from tblusrrating where  mdlid=21 and ShrId=p.usrprflId and usrid=@usrid) as ratests ,             
(select (cast(max(rating)as float))/2  from tblusrrating where  mdlid=21 and ShrId=p.usrprflId and usrid=@usrid) as rated ,             
(select (sum((cast(rating as float))/2))/(select COUNT(usrid) from tblusrrating where  mdlid=21 and ShrId=p.usrprflId) from tblusrrating where  mdlid=21 and ShrId=p.usrprflId) as rating,           
(select COUNT(usrid) from tblUsrShrCmntOn where UsrShrId=p.usrprflId and ShrTypId=21) as commntd,           
(select COUNT (tl.usrid) from tblUsrLike tl where tl.shrtypId=21 and tl.usrShrid=p.usrprflId and tl.sts=1) as liked,           
(select tls.sts from tblUsrLike tls where tls.shrtypId=21 and tls.usrShrid=p.usrprflId and tls.usrid=@usrid) as likedsts,           
(select COUNT(td.usrid) from tblUsrDislike td where td.shrtypId=21 and td.usrShrid=p.usrprflId and td.sts=1) as disliked,          
(select tds.sts from tblUsrDislike tds where tds.shrtypId=21 and tds.usrShrid=p.usrprflId and tds.usrid=@usrid) as dislikedsts,          
          
          
          
   vw.name, ([dbo].[fn_subsubcat](p.usrprflId)) as subsubctgryname, cm.compnyname,p.estb, desg.desg, d.usrprflctgryId,  c.ctgname, p.usrprflid, p.usrid, prfname.usrprfltypeid, prfname.typename,sc.usrprflsubctgryId, sc.subctgryname, ('UserFiles/100/'      
  
+cast(p.usrid as varchar)+'/Evisitingcard/'+cast(prfname.usrprflTypeId as varchar)+'/' + cast(p.usrprflId as varchar)+'.'+RIGHT(p.imgurl, 3)) as imgurl, p.discriptn,p.InspBy,p.Achvmnts,p.Planing,p.Addrs1,p.contct1,p.Email,p.Websit from tblusrprfl p       
  
    
      
                        
          
  inner join (select distinct usrprflctgryId, usrprflSubctgryId , usrprflid from tblusrprfldtl) d on p.usrprflid=d.usrprflid                                 
  left join  tblUsrPrflSubCtgry  sc on sc.usrprflsubctgryId = d.usrprflSubctgryId                                
  left join tblusrprflctgry c on c.usrprflcatgryid=d.usrprflctgryid                    
  left join tblusrcompnystatic cm on cm.usrcompnyId=p.compnyid                   
  left join tblusrPrflDesgStatic desg on desg.usrjobDesgntnStaticId=p.desgid                           
  inner join vwfrndlistfld vw on p.usrId=vw.usrid               
                               
  inner join tblusrprfltypeStatic prfname on prfname.usrprflTypeId= p.usrprfltypeId where p.isdel !=1 and p.usrid=@usrid                            
  order by p.cdate desc                    
end