Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Friday, December 27, 2013

WCF: Contracts an Introduction

In WCF all services expose contracts. Now a question arises what is a contract?
 
Contract is a platform neutral and standard way of describing what the service does. There are four types of contracts,
  • Service Contracts
  • Data Contracts
  • Fault Contracts
  • Message Contracts
Here we will try to define and use of each contract type.
 
Service Contracts describe which operations the client can perform on the service.
 
Data Contracts define which data types are passed to and from the service. WCF defines implicit contracts for built in types int and string, but we can easily define explicit  opt-in data contracts for custom types.
 
Fault Contracts define which errors are raised by the service and how the service handles and propagates errors to its clients.
 
Message Contracts allow services to interact directly with messages.
 
We will look into each of these Contracts in later blogs.

WCF : Addresses an Introduction

Every WCF service is associated with an address which will be used by the client to access the service. A WCF address provides two important elements,
  • Location of the service
  • Transport Protocol
Location service indicates that the name of the target machine, site or network; a communication port, pipe or queue and an optional specific path, or URI
 
Transport Protocol also called as Transport Schema is used to communicate with the service. Normally WCF supports below transport schemas
  • HTTP or HTTPS
  • TCP
  • IPC
  • Peer Network
  • MSMQ
  • Service Bus
Normally addresses have the below format,
[base address]/[optional port]
 
At the same time the base address has the format,
[transport]://[machine name or domain][:optional port]
 
HTTP addresses uses the http for transport and can also use HTTPS for secure transport. Typically uses http addresses with outward facing internet based services and we can specify a port also. If a specific port is not provided it will take the default port. For HTTP it is 80 and for HTTPS it would be 443. A sample http address is as follows,
 
TCP addresses uses net.tcp for transport and typically include a port number. If the port number is not provided the default for the tcp address is 808. A sample tcp address is as follows,
net.tcp://localhost:8002/MyService
 
IPC Addresses or Inter Process Communication addresses use net.pipe for transport, to indicate the use of the Windows named pipe mechanism. In WCF, services that use IPC can only accept calls from the same machine. So we have to either provide the machine name or the localhost followed by a unique string for the pipe name. It is not possible for two named pipe addresses to share a pipe name on the same machine because we can open a named pipe only once per machine. A sample IPC address is as follows,
net.pipe://localhost/MyPipe
 
MSMQ or Microsoft Message Queue addresses use net.msmq for transport. We must specify the queue name. If the queue is private we must provide the queue type as well. Samples for the MSMQ is as follows,
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService
 
Windows Azure AppFabric Service Bus addresses use sb, http or https for transport and must include the service bus address along with the service namespace.
sb://MyNamespace.servicebus.windows.net/
 
Now you must have got an overall idea on different types of addresses used in WCF.

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...