Geeks With Blogs
Rajesh Pillai My experiments with asp.net mvc, jquery, wpf, silverlight, sharepoint, tdd and design patterns.

Building Blocks of Service

Service is a

  • Collection of operations that are exposed to the clients.
  • Service contract defines what operations are available and how clients use them.
  • Data contract describes data that the client and service can exchange.

Service Contracts

Service Contracts

  • Describe the operations supported by a service, the message exhange pattern used and format of each
    message.
  • ServiceContract attribute marks an interface as a service contract.
  • OperationContract attribute exposes methods of the interface.

Code snippet

[ServiceContract]
public interface IHelloService 
{
     [OperationContract]
     string SayHello (string yourName);
}

Data Contracts

A data contracts

  • Describes how CLR types are mapped to XSD schema definitions.
  • Enable complex types to be serialized and deserialized so it can be passed across.
  • DataContract attribute identiifes each class that can be serialized.
  • DataMember attribute identifies members that needs to be exposed to the clients.

Code snippet

Here's an example of a data contract for a account class.

[DataContract]

public class Account

{

    [DataMember]

    public sting AccountNo { get; set; }
    [DataMember]

    public sting AccountType { get; set; }

}

 
The DataContract is applied at the class level and the DataMember is applied at the individual member level.  
 

Endpoints

The client communicates with service  via endpoints.

  • Host application makes the service available by providing one or more endpoints to the clients.
  • Endpoint consist of
    - Address of service (Where?)
    - Binding (How?)
    - Contract (What?)
  • Client and Service use the same endpoint.

Address-Binding-Contract are the ABC's of service. 

Bindings

  • Specify how a service endpoint communicates with client endpoints.
  • Consist of binding elements describing some essential aspect of communication like
    - Transport (HTTP, TCP, etc)
    - Protocol (security, reliability, transctions, sessions etc)
    - Messge encoding (text, binary etc)
  • Can be declared programatically or declaratively in the config file.

Out of box Bindings

  • BasicHttpBinding
    Compatible with ASMX Web Services.
  • WSHttpBinding
    - Conforms to WS* specifications for reliability, security and transactions.
    - Default
  • WS2007HttpBinding
    - Conforms to OASIS specifications for reliability, security and transactions.
  • WSDualHttpBinding
    - Supports WS-* + two-way communication
  • WSFederationBinding
    - Supports the WS-Federation specification for sharing identities across multiple systems.
  • WS2007FederationBinding
    - Supports federated security.
  • NetTcpBinding
    - Communicates across processes and machines.
  • NetNamedPipeBinding
    - Communicates on same machine
  • NetPeerBinding
    - Peer to peer communications over TCP
  • NetMsmqBinding
    - Uses MSMQ to transmit messages
  • MsmqIntegrationBinding
    - Service can send or receive messages from a MSMQ queue.

The most frequently used binding is the BasicHttpBinding, the WSHttpBinding and the NetTcpBinding.

That's it for now!!!

Posted on Sunday, December 20, 2009 9:14 PM wcf , SOA | Back to top


Comments on this post: WCF 2 - Building Blocks

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Rajesh Pillai | Powered by: GeeksWithBlogs.net