History of Distributed Applications
Monolithic applications gave way to applications built with components using COM • Desktop COM gave way to distributed COM (DCOM) • DCOM evolved into COM+ and integrated with Microsoft Transaction Server • .NET components can use enterprise Services to leverage COM+ • .NET remoting consists of a client and remote objects hosted on a remote server • Client can access remote objects as if they were local • Enterprise Services and .NET Remoting require client components and data to be on same network • Web Services enable you to pass as XML over Internet(Sample object Access Protocol(SOAP) defines structure of XML message client and services pass)
Service Oriented Architecture
• A service is a program that performs a task and that you can interact with through well-defined message • A service-oriented application consists of loosely coupled services that communicate through message and contracts(Client dose not instantiate the service) • Shift from remotely invoking components to passing message between services(Evolution of the development model for building distributed applications)
Principles of Service Orientation
Boundaries are explicit
• Services communicate by sending message across their boundary • All communication occurs through message
Services are autonomous
• You build, manage and version services independently • You can change a service without affecting clients as long as clients can continue sending and receiving the same message
Services share contracts and schema
• Contracts describe the message services can send and receive • Schemas define how the client and service construct the message they exchange
Compatibility is policy based
• Services can define the circumstances under which clients can communicate with them
What’s Wrong with What we Have?
Too many ways to create distributed applications
• Web services (SOA) • Enterprise Services, .NET Remoting (not SOA)
Which should you use and when?
• Do you need interoperability? • Are you going over the Internet or over TCP? • Are you accessing services internally or externally?
How easy is it to change from one to another?
WCF to the Rescue
• WCF provides unified programming model for building service oriented applications • One model whether communication is internal or external • Same service can be exposed over multiple protocols without duplicating effort or switching technologies
WCF vs Web Services
• Send message via not only HTTP , but also TDP and other protocols • Send messages using formats other than SOAP • Representational state transfer(REST) and plain Old XML(POX) • Host service on hosts other than a web server • Built-in support for transactions and reliable sessions • Built-in support for managing configurations , tracing and logging messages
Windows Communication Foundation(WCF)
• Unified programming model for building service oriented applications • Next generation of distributed applications and Web services • Part of .NET Framework 3.0 and 3.5 • Consists of a runtime and classes in • System.ServiceModel namespace
Let’s go bulid are first very sample WCF service:
1. Click Create new Project 2. Select WCF node 3. Select WCF Service Library 4. Wite name HelloWorldService
Full Size Image
5.Click OK.
Visual Studio created Project, and added
Sysytem.ServiceModel in Refrences.
Get Code
IService1
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
[ServiceContract]
public interface IService1
{
[OperationContract]
String SayHello(String yourName);
}
Service1
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
public string SayHello(String yourName)
{
return String.Format("Hello {0}", yourName);
}
Build Solution and Start Debugging.
Full Size Image
Double click (sayHello())
Full Size Image
Write your name and click Invoke:
Full Size Image
This attachment is hidden for guests. Please log in or register to see it.