Oops! That was a surprise when I added a WCF RIA services to my Silverlight application.
“This operation is not supported for a relative URI”
Well. Nothing to Panic. It’s a known issue in Visual Studio 2010, when you try to add a Service Reference in a Silverlight project. Simply Ignore it, your service will be added successfully.
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:
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
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.
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:
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
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.
IPC Binding (NetNamedPipeBinding)
Uses named pipes as a transport for same-machine communication and is lighter protocol than TCP binding.
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.
MSMQ Binding (NetMsmqBinding)
Uses MSMQ for transport and offers support for disconnected queue calls and is suitable for cross-machine communication.
Besides these, there are other less frequently used bindings:
WS Dual Binding (WSDualHttpBinding)
Peer Network Binding (NetPeerTcpBinding)
Federated WS Binding (WSFederationHttpBinding)
Federated WS 2007 Binding (WS2007FederationHttpBinding)
MSMQ Integration Binding (MsmqIntegrationBinding)
WS 2007 Binding (WS2007HttpBinding)
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
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.
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.
Defines which errors are raised by the service and how the service handles and propagates errors to its client.
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.
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=220.127.116.11, 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:
- IIS is installed after installing .NET Framework 4.0
- 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: