Friday, January 30, 2015

Web API vz WCF

What is “WebAPI”?

 HTTP is the most used protocol. For past many years browser was the most preferred client by which we can consume data exposed over HTTP. But as years passed by client variety started spreading out. We had demand to consume data on HTTP from clients like mobile,javascripts,windows  application etc.
For satisfying the broad range of client “REST” was the proposed approach. 

“WebAPI” is the technology by which you can expose data over HTTP following REST principles.


But WCF SOAP also does the same thing, so how does “WebAPI” differ?


SOAP
WEB API
Size
Heavy weight because of complicated WSDL structure.
Light weight, only the necessary information is transferred.
Protocol
Independent of protocols.
Only  for HTTP protocol
Formats
To parse SOAP message, the client needs to understand WSDL format. Writing custom code for parsing WSDL is a heavy duty task. If your client is smart enough to create proxy objects like how we have in .NET (add reference) then SOAP is easier to consume and call.
Output of “WebAPI” are simple string message,JSON,Simple XML format etc. So writing parsing logic for the same in very easy.
Principles
SOAP follows WS-* specification.
REST principles. (Please refer about REST in WCF chapter).


With WCF also you can implement REST,So why "WebAPI"?

WCF was brought in to implement SOA, never the intention was to implement REST."WebAPI'" is built from scratch and the only goal is to create HTTP services using REST.

Wednesday, January 21, 2015

SQL row merging


Given Table
ID  VAL1    VAL2
1     5          NULL
2     NULL     2
1     NULL     2
2     3          NULL

Expected Table
ID  VAL1 VAL2
1      5       2
2      3       2

 
Query
select * from 
(select distinct s1.id, s1.val1, s2.val2
from sample as s1
inner join sample as s2on s1.id = s2.id) t 
where t.val1 IS NOT NULL and t.val2 IS NOT NULL