CameTooFar

A Nerd's False Positive.

ABC of Windows Communication Foundation


Getting started with a new Technology is a big deal, specially when there exists a hell lot of terms, to be known. So, I took some time to pin-down the must-known terms in WCF, which is often termed as The ABC of WCF.

A – Where it Is?

Address, specifies where the service is located. The Address provides two important elements: the location of the service and the transport protocol (or transport scheme), used to communicate with the service.

Address Format: [base address]/[optional URL]

Base Address Format: [transport]://[machine or domain][: optional port]

Following transport schemes are supported:

  • HTTP/HTTPS

    Transport Format :  Http or Https
    Default Port           :   80 (Http), 443(Https)
    Note : Two HTTP addresses from the same host can share a port, even on same machine

  • TCP

    Transport Format : net.tcp
    Default Port           : 808
    Note : You can configure TCP-based addresses from different service-hosts to share a port

  • IPC (Inter-Process Communication)

    Transport Format : net.pipe
    Note : You can open named-pipe only once per machine, so it is not possible for two named pipe addresses to share a pipe name on the same machine.

  • Peer Network

  • MSMQ (Microsoft Message Queue)

    Transport Format : net.msmq

  • Service Bus (Windows Azure App Fabric Service Bus)

    Transport Format : sb

B – How to Communicate with it?
Binding, specifies which of various standard communication protocols the service understands. It is merely a consistent, canned set of choices regarding the transport protocol, message encoding, communication pattern, reliability, security, transaction propagation and interoperability.

The most common 5 bindings are:

  1. Basic Binding ( BasicHttpBinding )

    Is designed to expose a WCF service as a legacy ASMX web service (WS-I Basic Profile 1.1) so that old clients can work with new services
  2. TCP Binding (NetTcpBinding)

    Uses TCP for cross-machine communication on the intranet and provides – reliability, transactions, security and is optimized for WCF-to-WCF communication.
  3. IPC Binding (NetNamedPipeBinding)

    Uses named pipes as a transport for same-machine communication and is lighter protocol than TCP binding.
  4. Web Service (WS) Binding (WSHttpBinding)

    Uses HTTP/HTTPS for transport and provides – reliability, transaction, security; all using the WS-* standards. It is designed to interoperate with any party that supports the WS-* standards.
  5. MSMQ Binding (NetMsmqBinding)

    Uses MSMQ for transport and offers support for disconnected queue calls and is suitable for cross-machine communication.
Name Transport Encoding Interoperable
BasicHttpBinding HTTP/HTTPS Text/MTOM Yes
NetTcpBinding TCP Binary No
NetNamedPipeBinding IPC Binary No
WSHttpBinding HTTP/HTTPS Text/MTOM Yes
NetMsmqBinding MSMQ Binary No

 

Besides these, there are other less frequently used bindings:

  1. WS Dual Binding (WSDualHttpBinding)
  2. Peer Network Binding (NetPeerTcpBinding)
  3. Federated WS Binding (WSFederationHttpBinding)
  4. Federated WS 2007 Binding (WS2007FederationHttpBinding)
  5. MSMQ Integration Binding (MsmqIntegrationBinding)
  6. WS 2007 Binding (WS2007HttpBinding)
  7. Web Binding (WebHttpBinding)

C – What it’ll do?
Contract, specifies the portType section, lists all the operations that the service can perform by defining the message that it’ll emit in response to message it receives. In short, Contract is a platform-neutral and standard way of describing what the service does.

WCF defines 4 types of Contracts

  1. Service Contracts

    Describes which operation the client can perform on the service. It has 2 types of Contracts:

    a. Service Contract – can be an Interface/Class which defines a Service contract in an application.

    b. Operation Contract – can be a Method which defines an operation that is part of service contract.
  2. Data Contracts

    Defines what data-types are passed to and from the service. It has 2 types of contracts:

    a. Data Contract – Specifies the type defines or implements a data contract and is serializable by a serializer. It can be a Class/Struct/Enum.

    b. Data Member – Specifies the member is part of a DataContract and is serializable by the DataContractSerializer. It can be a custom Property/Field in the DataContract.
  3. Fault Contract

    Defines which errors are raised by the service and how the service handles and propagates errors to its client.
  4. Message Contract

    Allow the service to interact directly with messages. They can be typed or untyped and are useful in interoperability cases when another party has already dictated some explicit (typically proprietary) message format.

Hope this helped.

Happy WCFing.

WCF - Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0’


That was a surprise, when I run my first WCF application in .NET 4.0. I’s blown with an error:

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Have you noticed the error message where the System.ServiceModel has version 3.0. Yup, That’s it!

This error can occur in 2 scenarios:

  1. IIS is installed after installing .NET Framework 4.0
  2. Version 3.0 of WCF Http Activation Module is installed after installing IIS and .NET Framework 4.0

However, this can be easily solved by registering the correct version of ASP.NET. So, fire up your Visual Studio 2010 Command Prompt or browse to "C:\Windows\Microsoft.NET\Framework\ v4.0.30319". And run the following command from the command prompt:

aspnet_regiis.exe -iru

Happy Servicing!

Thanks