WCF - Endpoints : What are ABC's WCF?

 

Relationship between Address, Contract, Binding and Behaviors is called Endpoint.

Each endpoint consists of four properties: Address, Contract, Binding and Behaviors

  1. Address (A)
    • Defines where the service resides.
    • Indicates where to find the endpoint.
  2. Binding (B)
    • Defines how to communicate with the service.
    • Specifies how a client can communicate with the endpoint.
    • Specifies how the two parties will communicate in term of transport and encoding and protocols.
  3. Contract (C)
    • Defines what the service does.
    • Identifies the methods available.
    • Its Interface between client and the server.It’s a simple interface with some attribute.
  4. Behaviors
    • Customizes the local behavior of the service endpoint.
    • Participate in the process of building a WCF runtime.
    • Specify a different listening address than the SOAP or Web Services Description Language (WSDL) address.

 

 


What is difference between data Contracts and Message contracts?

WCF Contract:

  • Defines what the service does.
  • Identifies the methods available.
  • Its Interface between client and the server. It’s a simple interface with some attribute.

 

  Data Contracts Message Contracts
Definition Data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body
Describes Describes type of data

Describes structure of SOAP.

Message Contract is an abstraction over a SOAP message that allows you to explicitly dictate the structure of the underlying message.

Defines Data Structure Yes No
Generate Xml No Yes
Controls Controls content of SOAP message Controls structure of SOAP message

 


WCF - Bindings

What a Binding Defines?

  • Protocols
    • Determines the security mechanism being used: either reliable messaging capability or transaction context flow settings.
  • Encoding
    • Determines the message encoding (for example, text or binary).
  • Transport
    • Determines the underlying transport protocol to use (for example, TCP or HTTP).

System-Provided Bindings:

  • BasicHttpBinding: An HTTP protocol binding suitable for connecting to Web services that conforms to the WS-I Basic Profile specification (for example, ASP.NET Web services-based services).

  • WSHttpBinding: An interoperable binding suitable for connecting to endpoints that conform to the WS-* protocols.

  • NetNamedPipeBinding: Uses the .NET Framework to connect to other WCF endpoints on the same machine.

  • NetMsmqBinding: Uses the .NET Framework to create queued message connections with other WCF endpoints.

 



Differences between WCF Services and ASP.NET Web Services

  WCF ASP.NET Web Service
Class Attributes [ServiceContract] [WebService]
Method Attributes [OperactionContract] [WebMethod]
Actual Class Defrived from [ServiceContract] Definition  
Host Hosted in IIS, Windows Service, WAS (Windows Activation Service) Hosted in IIS
Access Protocal HTTP, TCP, MSMQ, P2P, NamedPipes HTTP
Supported Services Security, Transaction, Reliability, REST Support, Interoperability, Durable Massages, Service Orientation, Service Metadata, etc Security Service
Client Generation Using service metadata tool - svcUtil.exe Using command line tool - WSDL.EXE
Exception Handling

Unhandled exceptions are returned to the client as SOAP faults.

Configuration Service is provided to be configured to return an error code to the client for the debuggin purpose.

<serviceBehaviors>

  <behavior name="ServiceBehavior">

    <serviceMetadata httpGetEnabled="true"/>

    <serviceDebug includeExceptionDetailInFaults="true"/>

  </behavior>

</serviceBehaviors>

Unhandled exceptions are returned to the client as SOAP faults.
WSDL Customization WSDL can be customized using ServiceMetadataBehaviour class WSDL can be customized using ServiceDescriptionFormatExtension class
Serialization

System.RunTime.Serialization supported

  • Better performance
  • Hashtable can be serialized
  • Only classes that implement IDictionary can be serialized
  • DataContract and DataMember attribute are to indicate that these can be serialized.

System.XML.Serialization supported

  • Worst performance
  • Hashtable can not be serialized
  • Only calls that implement IEnumarable and ICollection can be serialized
  • Only public fields and properties can be serialized 
Multithreding Can be multithreaded by ServiceBehaviour class Can not be multithreaded
Supported Bindings BasicHttpBinding, WSHttpBinding, WSDualHttpBinding, SOAP and XML