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

Saturday, January 05, 2013

SOA - SOAP – WCF camp vs. ROA - REST – HTTP - ASP.NET Web API camp: Which one to choose?


 
Connected Systems:
One of the biggest challenges / opportunities in the industry is the integration and reuse of the existing systems.  Connectivity (Connect people, organizations, and existing systems) through connected applications becomes the key factor in the software development.  Solution to this challenge lies on developing interoperable, loosely coupled, secure distributed application.  
Around a decade back, Web Services and other RPC style framework assists the developers to build distributed applications.  The Windows Communication Foundation (WCF) simplifies development of connected applications through a new service-oriented managed programming model.  WCF takes Web services to the next level by providing developers with a highly productive framework for building secure, reliable and interoperable applications that send messages between services and clients.  WCF is pretty much mature now with .NET 4.5.
At the same time, there is another camp/ community where started using REST (Representational State Transfer) which is another different, alternative architectural style for building resource oriented services. The REST architectural style was developed by W3C Technical Architecture Group in parallel with HTTP/1.1. The World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture. . Unlike SOAP, Restful services simply relies on the HTTP application protocol verbs (GET – Fetch, PUT – Replace, POST – Insert and DELETE – Delete etc…). REST was initially described in the context of HTTP, but it is not restricted to HTTP protocol alone. RESTful architectures may be based on other Application Layer protocols, but in real time, it is only used with HTTP.
At this moment, REST approach is gaining upper hand because of its simplicity and reach. Restful services won’t require any proxies to consume and it be reached by a variety of device and client platforms. Microsoft have seen the increase in emergence of Restful services exposed over plain HTTP rather than through a more formal RPC style (like SOAP or WS*).  Microsoft already moved many of its implementations away from SOAP based technologies to REST. But WCF is not dead yet, it is still very well alive and in certain scenarios, it fit’s better than REST. 
 
 
SOAP vs. HTTP
Before going into WCF vs. Web API discussion, I would like to discuss more on some fundamentals. Any technology you mention which has its own merit and drawback. SOAP and HTTP protocols have different purpose and usage.
Simple Object Access Protocol, is a communication protocol specification for exchanging structured information over HTTP. It is based on XML and platform, Language independent. It build on top of HTTP as an abstraction layer. From the past decade, everyone agrees that HTTP is the correct intended way for communication between applications over traditional remote procedure calls (RPC) between objects like DCOM and COBRA. SOAP is designed be versatile enough to allow multiple or any transport protocols including HTTP, SMTP, TCP, UDP, Named pipes or even JMS. One thing, I learned in the last few years in program management is any system which performs more than couple of intended functionality will eventually fail.
SOAP actually was simple, but over time it tries to solve multiple enterprise demands like security, transaction, trust, discovery, federation etc. and slowly becomes complex and less interoperable. But if you want any of the WS-* specification feature, SOAP is the correct approach. For example: SOAP provides end-end message security compare to point to point communication. If the SOAP message is routed via multiple intermediaries before reaching the last receiver, the message itself is not protected once an intermediary reads it. Another example, say if you want a distributed transaction feature in your services, SOAP supports distributed transactions through the WS-Atomic Transaction (WS-AT) specification. Of course there are ways to achieve transaction in REST approach, but SOAP, WS-* make the implementation easy.  
On the other hand, Hypertext Transfer Protocol (HTTP) is an application, communication protocol which is more than a simple transport protocol. HTTP itself provides most of the features like authentication, caching, and content-type negotiation, so why an additional abstraction layer or different protocol – SOAP which is on top of HTTP anyway. In many scenarios, where you want to build services where the goal is reaching multiple devices, client platform, highly scalable, easy to consume, REST / HTTP services is the correct option. You can make REST / HTTP services secure, as similar to SOAP via HTTP authentication along with HTTPS.
The key advantage with RESTful services are simpler and better reach. Is Web Popular?! ;) Web - WWW, which is omnipresent everywhere now. Almost everyone knows about Web. HTTP/RESTful Services simply follows the tenets of the web which provides the same reach to people. I will give you a specific example - Just think of accessing a Service as below. You can access whatever the book detail of any author you want through HTTP GET itself! No Soap Messages, Proxy etc.
amazon.com/authors/{author}/{book}
Ex: amazon.com/authors/ArunGanesh/VS2010
 
amazon.com/authors/{author}?book={book}
Ex: amazon.com/authors/ArunGanesh?book=VS2010
HTTP provides the following nine methods or verbs that we can perform on an identified resource.
  • HEAD – Similar to a GET request without the response body. This is useful for retrieving meta-information written in response headers.
  • GET - Requests to just retrieve the specified resource.
  • POST – Client sends data (message body) to the server for an action.  
  • PUT - Uploads or updates the resource.  
  • DELETE deletes the specified resource.  
  • TRACE - allows the client to see what is being received at the other end of the request chain and use that data for testing or diagnostic information  
  • OPTIONS Returns the HTTP methods that the server supports for specified URL.  
  • PATCH Is used to apply partial modifications to a resource. 
1.       In Web, every resource being referred by a unique identifier, also known as a universal resource identifier (URI).
a.       URL+URN = URI. URI / Segment of a URI map to Application Logic. In the above example you can see that the segment of the URL itself being mapped to an application logic.
2.       Utilize HTTP Verbs - HTTP GET, POST, PUT, DELETE etc.
3.       Utilize HTTP Headers for representing what content type is required and services is returning. For instance, you can represent things like: languages, authentication, authorization, accepted encoding, char set, content type, length etc...
ASP.NET Web API:
ASP.NET Web API is a framework for building and consuming HTTP services. It’s latest Microsoft platform for building RESTful services. ASP.NET Web API takes the best features from WCF Web API and merges them with the best features from MVC!
 
 
It supports the following features:
  • Modern HTTP programming model
  • Easily define your URI space using the flexibility of ASP.NET Routing
  • Rich support for formats (JSON, XML, form URL encoded, OData, custom) and HTTP content negotiation
  • Request validation using data annotations
  • Automatically generate rich help page documentation for your web APIs
  • Content negotiation and custom formatters
  • Filters
  • Code-based configuration
  • Server-side query composition
  • IIS hosting or Self-host
  • Link generation
  • Testability
  • IoC integration
  • Tracing
  • VS template, scaffolding
 
Check out this article to get an idea around implementation is of ASP.NET Web API: http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api. You would have noticed how much it is integrated and part of ASP.NET MVC. 
I see WCF/ SOAP and ASP.NET Web API/ HTTP as two separate service design options that you need to choose wisely based on your current scenario.

 
Scenario
WCF 4.5
ASP.NET Web API
Need to support specific scenarios like Message queues, duplex communication, end to end message security, distributed transactions, one way messaging etc….
X
 
Already you have existing working WCF services and would like to add HTTP support additionally.
X
 
One code base to support both SOAP and RESTful endpoints
X
 
Need to create a resource-oriented services over HTTP
 
X
Your project is a MVC application and want to expose some functionality over HTTP
 
X
Want to build only a HTTP / RESTful services
 
X
Duplex communication over HTTP
SQL backend and need to expose OData endpoints
WCF Data Services


 

Saturday, December 15, 2012

Why the move from WCF to ASP.NET Web API?


Web Services (SOAP) to WCF (SOAP + WS-*) to WCF 3.5 (SOAP+ WS-* + HTTP request - WebHttpBinding) to WCF REST Starter Kit (REST part of WCF) to WCF Web API to ASP.NET Web API (Moved away from WCF to ASP.NET MVC)

As REST/ HTTP services start getting popular around .NET 3.5 time frame, Microsoft introduces features - WebHttpBinding  part of WCF 3.5 and WCF REST Starter Kit to create RESTful services. The REST starter kit tries to enrich the support of WCF 3.5 for HTTP services.
 
WCF 4.0 and 4.5 introduces few other feature set along with WCF Web API and tries to simplify the development of HTTP / Restful services.  Check this post - http://arunmvp.blogspot.com/2011/07/whats-new-in-wcf-40.html  on the .NET 4.0 features. But the key challenge is WCF is built on top of SOAP stack and treats HTTP as a transport instead of as an application protocol. ASP.NET Web API is all about HTTP and moreover already one can start develop a service which can return JSON from an ASP.NET MVC controller.
End of the day, ASP.NET provides a first class support for HTTP programming model and it make sense and easy for Microsoft to build Web API’s in ASP.NET MVC world rather than in WCF world.

Sunday, January 23, 2011

WCF Data Services

WCF Data Services
The Open Data Protocol, referred to as OData, is a new data-sharing standard that breaks down silos and fosters an interoperative ecosystem for data consumers (clients) and producers (services) that is far more powerful than currently possible.

Tuesday, January 26, 2010

WCF Bindings

Binding: How do I communicate to the service?


· Binding provides information on how a service can be accessed including transport method (HTTP / HTTPS / TCP / Named pipe / MSMQ), encoding format (Text / Binary /MTOM), security mechanism, reliability requirement etc...

 - A service to be accessible, at least it should be associate with either one or more bindings.
- A contract can support many bindings and a binding can support many contracts.
· Out of the box, Indigo support following bindings which covers most of the common scenarios.
- Developers can create their own custom binding based on their requirement with the mix of functionality.

Bindings ship with WCF
  • basicHttpBinding - Suitable for communicating with WS-Basic Profile conformant Web services
  • wsHttpBinding - Secure and interoperable binding that is suitable for nonduplex service contracts.
  • wsDualHttpBinding - Secure and interoperable binding that is suitable for duplex service contracts. 
  • wsFederationHttpBinding - Secure and interoperable binding that supports the WS-Federation protocol 
  • netTcpBinding - Secure and optimized binding suitable for cross-machine communication between WCF applications. 
  • netNamedPipeBinding - Secure, reliable, optimized binding that is suitable for on-machine communication between WCF applications. 
  • netMsmqBinding - A queued binding that is suitable for cross-machine communication between WCF applications. 
  • netPeerTcpBinding - A binding that enables secure, multimachine communication. 
  • msmqIntegrationBinding - A binding that is suitable for cross-machine communication between a WCF application and existing Message Queuing applications. 
  • webhttpbinding is a new Web Friendly Binding which is used for services that are exposed through HTTP requests (Not through SOAP).

 Let's see a quick example:


In the above configuration, you can see we have multiple endpoints which expose the contract: MyExample.IBook.


Endpoint 1 : Address is Empty, which means which will take the base address. Binding is wsHttpBinding.
End Point 2: Address is having "/basic" which implies the address is: http://localhost:8000/example/service/basic. Binding is basicHttpBinding.
Endpoint 3: NamedPipe Address and binding.
Endpoint 4: TCPIP Address and related binding.


 The above simple configuration is enough to expose your service different way.

WCF provides key characteristics like Transport Neutral (Http, TCP, MSMQ and Named Pipes), various security features, multiple messaging patterns (simplex, duplex and request reply), encodings (text, binary or MTOM), network topologies, and hosting models (Windows, Windows NT Service, Console and IIS).

The above example shows you the that how WCF is one single programming model and runtime which unifies of existing .NET Framework communication technologies like ASMX, Remoting, Enterprise Services, WSE, MSMQ etc...

RESTful Services

What is REST?
REST defines an architectural style for building services in the “Web” way. It is one of the Buzz word, all together a different thought process!
REST is not tied to any particular technology or platform – it’s just another way to design things to work like the Web. Again this is not something new. REST concept exists for a long time but not utilized to its full power.
 
Definition:
"Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The term Representational State Transfer (REST) was introduced and defined in 2000 by Roy Fielding[1][2] in his doctoral dissertation. Fielding is one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification versions 1.0 and 1.1." - From wikipedia.org

Why REST Popular?

Is Web Popular?! ;) Web - WWW, which is omnipresent everywhere now. Almost every one knows about Web. RESTful architecture simply follows the tenets of the web which provides the same reach to people.
I will give you a specific example - Just think of accessing a Service as below:

You can access whatever the book detail of any author you want through HTTP GET itself! No Soap Messages, Proxy etc.

amazon.com/authors/{author}/{book}
Ex: amazon.com/authors/ArunGanesh/VS2010

amazon.com/authors/{author}?book={book}
Ex: amazon.com/authors/ArunGanesh?book=VS2010

Key Items to remember:

1. In Web, every resource being referred by a unique identifier, also known as a universal resource identifier (URI). URL+URN = URI

URI / Segment of a URI map to Application Logic. In the above example you can see that the segment of the URL itself being mapped to an application logic.

2. Utilize HTTP Verbs - HTTP GET, POST, PUT, DELETE etc.

3. Utilize HTTP Headers for representing what content type is required and services is returning. For instance, you can represent things like: languages, authentication, authorization, accepted encoding, char set, content type, length etc...

Monday, January 25, 2010

WebHttpBinding Class

Check this out, if you are new to word - Binding: WCF Fundamentals - One should Know!

WebHttpBinding is a new Web Friendly Binding which is used for services that are exposed through HTTP requests (Not through SOAP).

The WCF Web Programming Model allows developers to expose services through HTTP requests instead of SOAP-based messaging.

Key Items:
1. Binding to build RESTful Servcices
2. HTTP - No to SOAP
3. HTTP and HTTPS Transport.

Support Several Formats like: XML, JSON (Javascript Object Notations) and Binary Streams

Sunday, January 24, 2010

My Community Tech Days Presentation

Please download my today's presentation at:
https://arunmicrosystems.sslpowered.com/WCF_Arun.pdf

Please let me know if you any queries related to session topic.

Saturday, February 21, 2009

New Release: patterns & practices WCF Security Guide

New Release: patterns & practices WCF Security Guide Using end-to-end application scenarios, this guide shows you how to design and implement authentication and authorization in WCF. You'll learn how to improve the security of your WCF services through prescriptive guidance including guidelines, a Q&A, practices at a glance, and step-by-step how to articles.

Tuesday, January 20, 2009

Service Configuration Editor







Service Configuration Editor





· Windows Communication Foundation (WCF) Service Configuration Editor enables administrators and developers to create and modify configuration settings for WCF services using a graphical user interface (GUI).



· With this tool, you can manage settings for WCF bindings, behaviors, services, and diagnostics without having to directly edit XML files.



- The file SvcConfigEditor.exe present in the location: C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin

Service Trace Viewer

· Windows Communication Foundation (WCF) Service Trace Viewer helps you analyze activity tracing (*.svclog) diagnostic traces that are generated by WCF listeners.

· Service Trace Viewer provides a way to easily merge, view, and filter trace messages so that you can diagnose, repair, and verify WCF service issues.


· To configure tracing for WCF messages, use Service Configuration Editor (SvcConfigEditor.exe).
· Try changing the binding to wsHttpBinding from basicHttpBinding in config file. You can see encrypted CipherValue rather than plain “Hello World” in the trace.

………
256
YG0GBisGAQUFAqBjMGGgJDAiBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAqI5BDdOVExNU1NQAAEAAAC3shjiBwAHADAAAAAIAAgAKAAAAAUCzg4AAAAPVi1ESkFDT0JGQVJFQVNU

Saturday, January 17, 2009

WCF Fundamentals - One should Know!

WCF Fundamentals

· Before switch to Programming gear in the upcoming blogs, let’s have a quick look on some fundamental concepts.

· WCF programs communicate through the exchange of messages.

- A message is a self-contained unit of data consists of header and a body.

- A message should contain one body and any number of headers.

- All Indigo messages are represented as XML, specifically SOAP envelopes containing XML
Infosets.

· There are three types of Messaging programs: Clients, Services and Intermediaries.

- Client program initiate and send the request message to Service program.

- Service program respond to the client message. The input message may cause the service to perform some action like code execution or reply back to the client with an output message.

- Intermediary is a program between Service and Client which do some tasks like routing, acting as gateway, monitoring etc…

ABC’s of WCF

· Out of the box, WCF provides the following encodings:

- Text encoding, an interoperable encoding.

- Message Transmission Optimization Mechanism (MTOM) encoding, this is an interoperable way for efficiently sending unstructured binary data to and from a service.

- Binary encoding for efficient transfer.

· One can have more encoding mechanisms like a compression encoding using the built-in extension points of WCF.

· WCF supports the following messaging patterns

- Simplex – One Way Messaging (Fire and Forget).
- Duplex – Asynchronous two-way messaging. (Ex: Remotely controlled robot).
- Request: Reply – Synchronous two-way messaging. (Ex: XML Web services)


Indigo Service – Internally

· Internally, Indigo service contains contracts, bindings, endpoints and implementation code.

· Address: Where is the service?

· An address defines where messages can be sent. The format of an endpoint address depends on the transport mechanism.

- For instance, for HTTP Transport it looks like http://www.objectinnovations.com:8080/nf3

- For TCP, it looks likes net.tcp://www.objectinnovations.com:9000/nf3

- The endpoint address enables you to create unique endpoint addresses for each endpoint in
a service.

· Binding: How do I communicate to the service?

· Binding provides information on how a service can be accessed including transport method (HTTP / HTTPS / TCP / Named pipe / MSMQ), encoding format (Text / Binary /MTOM), security mechanism, reliability requirement etc...

- A service to be accessible, at least it should be associate with either one or more bindings.

- A contract can support many bindings and a binding can support many contracts.

· Out of the box, Indigo support following bindings which covers most of the common scenarios.

- Developers can create their own custom binding based on their requirement with the mix of functionality.

· Contract: What can the service do for me?

- A contract explains a service’s behavior, structures, or message formats.

- There are three types of contracts in Indigo Services including Service contracts, Data contracts and Message contracts.

· You define service contracts, data contracts, and message contracts by using declarative attributes.

· The class that needs to be exposed as a WCF service should be marked with ServiceContract attribute.

· Service contracts can be defined by annotating an interface with [ServiceContract].

· Identify service operations by annotating methods with [OperationContract].

· A service contract defines service-level settings, such as the namespace of the service, a corresponding callback contract, etc.

- In comparison to object oriented programming, the service contract is nothing but an interface.

- All methods that need to be invoke using SOAP message should be marked with OperationContract attribute.

- An operation contract defines the parameters and return type of an operation.

· A WCF service can have multiple service contracts.

· For instance, a service contract looks as follows:
[ServiceContract]

public interface IBook
{
[OperationContract]
bool BookAvailable(string bookName, string authorName, int bookID)
[OperationContract]
bool AddCart(Book book)
[OperationContract]
void OrderBook(int bookID)
}

· By default service contracts handle simple service calls. Data contract defines custom data structures like object or struct.

· If the service is using only simple types, there is no need to explicitly use data contracts. In Data Contracts, the data can be passed to and from services in XML Schema form.

· For instance, a data contract looks as follows:
[DataContract]
public class Book
{
[DataMember]
public string bookName;
[DataMember]
public string authorName;
………
}
· Contrast to ASMX Web services, in WCF you need to decorate a class with Data contract attributes, to allow serialization.

· Data Contract specifies how the data is serialized and de-serialized.

· A message contact describes the format of a message. For example, it declares whether message elements should go in headers versus the body, what level of security should be applied to what elements of the message, and so on.

· Externally, Indigo service exposes a service description (WSDL, WS-Policy) and one or more endpoints, with each endpoint exposing one or more service operations.

· An endpoint connects a contract and a binding with an address. At least one endpoint needs to be there to access that service. A service can have multiple endpoints.

· For instance,
- Endpoint1 = Address1 (http://www.objectinnovations.com/WCF/) + Binding1 (Http / X.509 Cert / MTOM Encoding) + Contract1 (IContract1 interface)
- Endpoint 2 = Address 2 (net.tcp://www.objectinnovations.com/WPF/) + Binding2 (TCP / Windows Security / Binary Encoding) + Contract2 (IContract2 interface)
- Endpoint 3 = Address3 (net.msmq://www.objectinnovations.com/WF/) + Binding3 (MSMSQ / Binary Encoding) + Contract2 (IContract2 interface)
- A service can have many endpoints (contract bound to address) coexisting and available at the same time.

Indigo Service – Externally

· If you want to expose your service via HTTP and use SOAP 1.1 for maximum interoperability, and also want to expose it via TCP using a binary wire encoding for maximum performance, the two resulting endpoints can reside side-by-side on top of the very same service!

- Endpoints: Addresses, Bindings, and Contracts!

· An endpoint consists of four properties:

- An address that specifies where the endpoint can be found.

- A binding that specifies how a client can communicate with the endpoint.

- The contract specifies what functionality the endpoint exposes to the client.

- A set of behaviors that specify local implementation details of the endpoint.

WCF - New Mantra to Connected World

· One of the biggest challenges / opportunities in the industry is the integration and reuse of the existing systems.

- Connectivity (Connect people, organizations, and existing systems) through connected applications becomes the key factor in the software development.

- Solution to this challenge lies on developing interoperable, secure distributed application using Service Orientation.

- For the last few years, Web Services assist the developers to build distributed applications.

· The Windows Communication Foundation (WCF), Microsoft’s next generation Web services technology, simplifies development of connected applications through a new service-oriented managed programming model.

- WCF takes Web services to the next level by providing developers with a highly productive framework for building secure, reliable and interoperable applications that send messages between services and clients.

- Windows Communication Foundation (formerly code-named "Indigo") is a set of .NET technologies which for building and running connected systems.

WCF Key Features
· WCF is the Microsoft service-oriented communication infrastructure and programming platform and runtime system for building, configuring and deploying network-distributed services.

- WCF is implemented in managed code as an extension of the Microsoft .NET Framework 2.0.

- WCF provides key characteristics like Transport Neutral (Http, TCP, MSMQ and Named Pipes), various security features, multiple messaging patterns (simplex, duplex and request reply), encodings (text, binary or MTOM), network topologies, and hosting models (Windows, Windows NT Service, Console and IIS).

- Unification of existing .NET Framework communication technologies like ASMX, Remoting, Enterprise Services, WSE, MSMQ etc...

- Implementing latest Web Services Standards / WS* Specifications and to support interoperability, including reliability, security, and transactions.

- Implicit use of service-oriented development principles.

Unified Programming Model
· Today we had distributed stacks of technologies like ASMX, WSE, Remoting, System.Messaging, Enterprise Services etc…

- AMX (ASP.NET Web Services) – To achieve cross-vendor interoperability (Interoperable, ASP.NET Integration)

- .NET Remoting - Tightly coupled .NET-to-.NET communication to achieve performance (Extensible and CLR Integration)

- Web Services Enhancements (WSE) – To implement WS-* specifications along with ASMX

- System. Messaging – Communication with Windows-based applications that require guaranteed data delivery. (Queuing, Reliable Messaging and MSMQ Integration),

- Enterprise Services - This handles things like components, activation, transactions and so on.

· Developers have had to use multiple technologies to build connected systems.

- Each stack has its own strengths and once you choose one technology, it is difficult to switch gear to another one.

- WCF combines and extends the functionality of existing Microsoft technologies (ASMX, .NET Remoting, .NET Enterprise Services, Web Services Enhancements, and System.Messaging) to deliver a single, highly-productive development framework that improves developer productivity.

· Indigo provides all these features through one unified programming model including
- Message oriented programming (System. Messaging)
- Implement WS* specifications (WSE)
- Achieve Extensibility and performance (Remoting)
- Service oriented programming and Interop (ASMX)
- Attribute based programming, object life time management, distributed transactions (Enterprise services).
- Wondering how? Will see one by one!
Interoperability with Applications
· Right now, XML Web services provide support for basic interoperability between applications running on different platforms.

- WCF delivers secure, reliable, transacted interoperability through built-in support for the WS-* specifications.

- For developers, this greatly reduces the amount of infrastructure code required to achieve interoperability along with other enterprise features.

· An application built on WCF can communicate with WCF-based applications running in a different process on the same Windows machine, WCF-based applications running on another Windows machine and applications built on other technologies, such as IBM WebSphere, BEA WebLogic, and other Web services built in J2EE that are standards compliant.

- These applications can be running on Windows machines or on machines running other operating systems, such as Sun Solaris, IBM z/OS, or Linux.

- WCF support various specifications/standards, including basic standards (XML, XSD, XPath, SOAP, WSDL) as well as advanced standards and specifications that comprise the WS-* architecture. These include: WS-Addressing, WS-MetadataExchange, WS-Policy, WS-Security, WS-Trust, WS-SecureConversation, WS-ReliableMessaging, WS-AtomicTransaction, WS-Coordination, WS-Policy, and MTOM.

Support for Service-Oriented Development

· Building adaptable solution which is flexible enough to the fast moving business and technological change is one of the biggest challenges faced by software industry.

- WCF is the programming model build up from scratch for building service-oriented application development.

· WCF completely supports the four tenants of Service Orientation.
- Boundaries are Explicit
- Services are Autonomous
- Services share schema and contract, not class
- Service compatibility is determined based on policy
· Applications based on the above four tenants provide benefits in maintainability, reusability, and manageability of connected systems.

· Service-oriented development complements object-oriented (OO) development. Still Object-oriented concepts will be used to implement internal design of services.

Sunday, November 23, 2008

Indigo Programming Model

Indigo Programming Model

· Indigo programming involves the use of an object model, declarative attributes, and configuration settings.

- Declarative programming. Usually Declarative attributes are used to define contracts and specify service behaviors.

- Imperative programming, in which you work with the Indigo object model in code.

- Configuration-based programming, in which you specify behavior in application configuration files. Configuration-based development helps to modify behaviors like addresses, bindings, security details, service behavior, tracing etc without recompile the program code.

· It’s not mean that you can do three different way of Indigo Programming. It is to say that WCF provide features to do few things in more than one way.

· For instance, An endpoint defined in a configuration file:


· The same endpoint definition in code:
serviceHost = new ServiceHost();
serviceHost.AddEndpoint(typeof(IMyContract), new WSProfileBinding(),
http://localhost:8000/MyService/);

Hello World WCF Service

· Let’s first see, how to develop a simple WCF service which simply returns “Hello World” when client connects to it.

· Service programs contain four elements: Contract definitions, implementation code, hosting code and Endpoint definitions.

namespace HelloService
{
class Infrastructure
{
static void Main(string[] args)
{

// A Uri, which represents the address of the service.
Uri baseURI = new Uri("http://localhost/helloworld");

ServiceHost HelloWCF = new
ServiceHost(typeof(HelloService), baseURI);

//Binding (BasicHttpBinding) provides how to communicate with the endpoint.

HelloWCF.AddServiceEndpoint(typeof(HelloService),
new BasicHttpBinding(), baseURI);
HelloWCF.Open();
Console.WriteLine("Hello World Service Started.");
Console.ReadKey();
HelloWCF.Close();
}
}


[ServiceContract]
class HelloWorld
{
[OperationContract]
string Hello()
{
return ("Hello World!");
}
}
}

- The [ServiceContract] attribute specifies that class will be exposed as a WCF service.

- The attribute [OperationContract] specifies that the Hello() function which returns the string “Hello World!" will be exposed as a method on that service.

- The class Infrastructure contains the basic infrastructure including "ServiceHost" which provides the hosting infrastructure for the service and the endpoint definition.

- BasicHttpBinding uses HTTP as the transport for sending SOAP 1.1 messages.

- A service can use this binding to expose endpoints that conform to WS-I BP 1.1, such as those that ASMX clients consume.

- Both classes and interfaces can be used to define a WCF service contract. It’s better to use Interfaces, because they directly model service contracts.

· Now, let's move the endpoint definition of the “HellowWorld” service from the code to the config file.

· The config file will be read at runtime. Therefore we can modify the binding details with out rebuild and restart of the application.

· Add a configuration file “app.config” and comment the code:

HelloWCF.AddServiceEndpoint(typeof(HelloService),
new BasicHttpBinding(), baseURI);

· Add the following configuration details in the app.config:

· If you run the service now, you will see an error message “Metadata publishing for this service is currently disabled.”

· By default, the framework does not expose any metadata.

- To expose the metadata required to generate the proxy, you must add a Element and set its httpGetEnabled attribute to True.

Hello World WCF Client

· To test our Service, let’s create a client. A client must create a proxy, which establishes a channel to the service.

· To generate client code from a service, we need to use the Svcutil tool. Svcutil not only generates contract code, but it also provides a proxy class for accessing the service.

· Clients create a new instance of the proxy, and they can then access the service through the proxy.

- svcutil http://localhost/hello?wsdl

- Then SvcUtil will get the WSDL file for the service, download the metadata, and generate the service proxy for you. Along with client code from a running service it also generates a config file.
· Add the proxy class and config file in the project and you can access the Service.