Thursday, October 13, 2011

Difference between ASP.NET Web Service and WCF

"width: 284pt;" width="378">

WCF 

ASP.Net Web Service
Data Representation

DataContractSerialier

XMLSerializer

very precise control over how a type is represented in XML

very little control over how a type is represented in XML

Not much control over the type serialization process becomes highly predictable for the DataContractSerializer, and, thereby, easier to optimize A practical benefit of the design of the DataContractSerializer
 is better performance, approximately ten percent better
performance.

DataMemberAttribute for use with the DataContractSerializer shows explicitly which fields or properties are serialized

We can't specify which fields or properties of the type are  serialized into XML

the DataContractSerializer can translate the members of
objects into XML regardless of the access modifiers of those members.

The XmlSerializer can only translate the public members
of a .NET object into XML

the DataContractSerializer has fewer restrictions on the
variety of .NET types that it can serialize into XML.
In particular, it can translate into XML types
like
Hashtable that implement the IDictionary interface

Classes that implement the IDictionary interface, such as
Hashtable, cannot be serialized into XML.
Hosting

the service file have .svc extension

#@ServiceHost

IIS, WAS, .NET application

the service file have .ASMX extension

#@WebService

IIS


Client development

servicemodel metadata utility tool (svcutil.exe)

Web service definition language (WSDL.exe)


Message Representation

SOAP message can be customized by MessageHeader,
MessageContract, MessageBodyMember

SOAP message can be customized by SoapHeader,
SOAPheaderAttribute


Service Description

WSDL generation of WCF can be customized not generate
instead use existing static WSDL itself

WSDL generation of ASP.NET can't be customized not generate 


Exception Handling

In WCF services, unhandled exceptions are not returned
to clients as SOAP faults to prevent sensitive information being inadvertently exposed through the exceptions.

In ASP.NET Web services, unhandled exceptions are
returned to clients as SOAP fault


State Management

The WCF provides extensible objects for state management.
 Extensible objects are objects that implement
IExtensibleObject. The most important extensible objects
are ServiceHostBase and InstanceContext. ServiceHostBase
 allows you to maintain state that all of the instances of all
 of the service types on the same host can access, while
InstanceContext allows you to maintain state that can
be accessed by any code running within the same
instance of a service type.

ASP.NET provides considerable control over where the
session state information accessed by using the Session
property of the HttpContext is actually stored.
It may be stored in cookies, in a database, in the memory
of the current server, or in the memory of a designated
server. The choice is made in the service’s configuration file.


Globalization

The WCF does not support that configuration setting
except in ASP.NET compatibility mode.
To localize a WCF service that does not use ASP.NET compatibility mode, compile the service type into culture-specific assemblies, and have separate culture-specific endpoints for each culture-specific assembly. 

The ASP.NET configuration language allows you to specify
the culture for individual services









No comments: