Wednesday, May 16, 2012
WCF Vs Web Services
WCF/ASP.Net Web Services are used for developing web services. Here is a list of differentiation between these two.
Feature | ASP.NET Web Service | WCF |
Data Transformation | To and from Data Transition is done through XML Serializer | DataContractSerializer is used for data transition |
File Extension | asmx | .svc |
Webmethods vs DataContract Attributes | ASP.NET WebService uses Webmethods to translate .NET FW types in to XML. | WCF uses the DataContractAttribute and DataMemeberAttribute to translate .NET FW types in to XML. |
Limitations | Only Public fields or Properties of .NET types can be translated into XML.Only the classes which implement IEnumerable interface. ICollection interface can be serializable | Public/Private fields or properties of .NET types can be translated. |
IDictionary Interface class | Classes that implement the IDictionary interface, such as Hash table can not be serialized. | The DataContractSerializer can translate the Hash Table into XML. Hence using WCF we can even translate HashTable into XML |
Security | WCF is more secured than WebService | It is based on WS Standards. capable to run in any .NET executable, so it needs independent security capabilities. Transfer security=Responsible for providing message confidentiality, data integrity, and authentication of communicating parties. |
Binding | Web service supports only HTTP. | WCF supports multiple bindings HTTP,TCP,MSMQ,WS-HTTP etc |
Messaging | ASP.Net web service uses only SOAP for sending and receiving data. It uses Xml Schema to defines structure of message. | WCF can send message in any format. It uses SOAP for communication by default. It can use any other transport protocol for message transport . |
Performance | Slower compared to WCF | The main advantage of the design of the DataContractSerializer is better performance over XML serialization |
Fields / Properties | XMLSerialization does not indicate the which fields or properties of the type are serialized into XML | DataContratSerializer Explicitly shows the which fields or properties are serialized into XML |
Exception handling | In ASP.NET Web services, Unhandled exceptions are returned to the client as SOAP faults. | In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to clients for the purpose of debugging. |
Example | [WebService] | [ServiceContract] |
After you know the importance of the WCF on WebServices, We can create our Sample WCF application in next blog post.
Monday, May 14, 2012
Understanding WCF
WCF brings all the formerly distinct and separate Microsoft connectivity technologies together under a single umbrella within the System.ServiceModel namespace. Web services (ASMX), the Web service Extensions (WS*), Microsoft Message Queuing (MSMQ), COM+, and .NET Remoting are included in WCF. With WCF you won't have to choose between implementations in a variety of different namespaces and coding types to create a connected application. Whether your application connects via loosely coupled Web services, or tightly coupled Enterprise Services, the coding model will be consistent and the transition between different communication types will be much smoother—because they will all be using the same programming namespace. WCF follows the "software as a service" model, where all units of functionality are defined as services. A WCF Service is exposed using End point. WCF Service can be deployed, discovered and consumed as Endpoint All communications with the WCF service will happen via the endpoints. The endpoints specify a Contract that defines which methods of the Service class will be accessible via the endpoint; each endpoint may expose a different set of methods. The endpoints also define a binding that specifies how a client will communicate with the service and the address where the endpoint is hosted. WCF provides Windows Activation Services which can be used to host the WCF service. Otherwise the WCF service can also be hosted in IIS or in any process by using the Service Host class, which is provided by WCF. Services can also be self-hosted. An End point is based on ABC. Address → Where Service is located. The address specifies the location of the service which will be exposed for clients that will use it to communicate with the service. The address's protocol that WCF can provided: HTTP , TCP ,NamedPipe , Peer2Peer ,MSMQ. [transport]://[machine][:optional port] http://localhost http://localhost:8081 http://localhost:8081/Service net.tcp://localhost:8082/Service net.pipe://localhost/Pipe Binding → How Service can be consumed/ used In other words: how the two parties will communicate in terms of transport (HTTP , TCP ,NamedPipe , Peer2Peer ,MSMQ) ,encoding (text, binary etc.) and protocols (like transactional support or reliable messaging). BasicHttpBinding NetTcpBinding WSHttpBinding NetMsqmqBinding Etc..
Contract → What is Available (Interfaces..) contracts available in WCF are: Service Contract – Exposes the service. Operation Contract- Exposes the service members. Data Contract – Describes service parameters. Fault Contracts – Defines error handling semantics Hosting WCF services must be hosted by a Windows Process (host process). Hosting options include: IIS 5 & 6. IIS 7 & Windows Activation Service (WAS). Console or Windows Forms applications (also called “Self-Hosting”) |
Review of Web services
Before we proceed further into WCF in future posts just let’s get a basic understanding on Web services. |
Web Service is a web application which expose list of methods (business logic) over Network. Web service uses 2 protocols. HTTP: For transportation. SOAP: For Messaging. Using a Web service, different applications developed in different technologies can communicate, called as interoperability. Sample Webservice: Let’s create a sample web service in ASP.Net Open Visual studio 2010 » File » New » Website » Select Visual C# Language » Select .Net Framework versions <4.0 » so we select 3.5 » select optional path required » This creates a sample Helloworld service » Execute the website » It displays the Service.asmx page with the hello world method » If you open that method » which further displays SOAP Messages with Envelope and Body in XML format. See the diagram for reference Limitations of Web service: Web service can be hosted only on IIS. Web services uses only HTTP Protocol. Web service doesn’t provide compression of SOAP Messages. Message Level Security is not provided by web services. No reliable Transaction Management. Microsoft and IBM has come up with Web service extensions like WS-Security, WS-Transactions etc.. which is different programming model. So WCF is introduced which is unification of all these technologies with a similar programming model. WCF is Framework introduced in .Net3.0 in year 2006. We shall discuss detailed Architecture and implementation of WCF in future posts. |