Attributes
WCF has [ServiceContract] attribute attached with the class.
WS has [WebService] attribute attached with the class.
WCF has [OperationContract] attribute attached with methods.
WS has [WebMethod] attribute attached with methods.
WCF has [ServiceContract] attribute attached with the class.
WS has [WebService] attribute attached with the class.
WCF has [OperationContract] attribute attached with methods.
WS has [WebMethod] attribute attached with methods.
Hosting
WCF can be hosted on IIS, WAS, of self-hosting.
WS can be hosted on IIS.
WCF can be hosted on IIS, WAS, of self-hosting.
WS can be hosted on IIS.
XML
WCF uses using System.Runtime.Serialization; namespace for serialization.
WS uses using System.Xml.Serialization; namespace for serialization.
WCF uses using System.Runtime.Serialization; namespace for serialization.
WS uses using System.Xml.Serialization; namespace for serialization.
Transports
WCF support HTTP, TCP, MSMQ, P2P transport protocols.
WS support Http protocol.
WCF support HTTP, TCP, MSMQ, P2P transport protocols.
WS support Http protocol.
Encoding
WCF supports XML, MTOM (Messaging Transmission Optimization Mechanism), Binary.
WS supports XML, MTOM, DIME (Direct Internet Message Encapsulation).
WCF supports XML, MTOM (Messaging Transmission Optimization Mechanism), Binary.
WS supports XML, MTOM, DIME (Direct Internet Message Encapsulation).
Security
WCF provides reliable security for messaging and transactions over net.
WS doesn’t provide method level security & message delivery isn’t assured & can be lost without acknowledgement.
WCF provides reliable security for messaging and transactions over net.
WS doesn’t provide method level security & message delivery isn’t assured & can be lost without acknowledgement.
Few Important points in WCF
Address
WCF service location that client can use to expose its features
Binding
Configuration for Transport protocol, security and encoding mechanism.
Contract
It defines type of data and type of operations, a client application can use from WCF service.
Service Contract in WCF
It has 2 attributes: [ServiceContract] and [OperationContract]
WCF service location that client can use to expose its features
Binding
Configuration for Transport protocol, security and encoding mechanism.
Contract
It defines type of data and type of operations, a client application can use from WCF service.
Service Contract in WCF
It has 2 attributes: [ServiceContract] and [OperationContract]
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
Data Contract in WCF
It has 2 attributes: [DataContract]and [DataMember]
It has 2 attributes: [DataContract]and [DataMember]
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
WCF configurations in config file
It declares information about endpoint name, address, binding and contract.
It declares information about endpoint name, address, binding and contract.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1"behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Responses
0 Respones to "What are the differences between WCF and Web Service"
Post a Comment