WCF
History of Distributed
Application
1.)
Monolithic applications give way to application with components using
COM.
2.)
Desktop COM gave way to distributed COM (DCOM).
3.)
DCOM evolved into COM+ and integrated with Microsoft Transaction server.
4.)
.NET components can use enterprise services leverage COM+
5.)
.NET Remoting consists of a client and Remote object hosted on a remote
server.
6.)
Enterprise service and .NET Remoting require client ,components and data
to be on the same network
7.)
Web services enable us to pass data as XML over internet
a.)SOAP (Simple
Object Access Protocol) defines structure of XML Messages Client and Services
pass.
Service Oriented Architecture
1.)
A service is a program
that performs a task that you can interact with through well defined messages.
2.)
A service-oriented
application consists of loosely couple service that communicate through
messages and contracts
a.)
Client does not
instantiate the service
3.)
Shift from remotely
invoking components to passing messages between services
a.)
Evolution of development model
for building distributed applications.
4.)
Service are autonomous
a.)
Build, manage and version
service independently(u can build
service independently and client invoke service independently)
b.)
Change a service without
affecting clients as long as clients can communicate send and receiving the
same messages.
5.)
Principles of service
orientation
a.)
Contracts describe the
messages services can send and receive
b.)
Schemes define how the
client and service construct the messages they exchange
6.)
Compatibility is policy based
a.)
Service can define the
circumstances under which clients can communicates with them.
What Wrong With What We Have?
1.)
Too many ways to crate distributed applications
a.)
Web services(SOA)
b.)
Enterprise Servicesn.Net remoting(not SOA)
2.)
Which should we used and when?
a.)
Interoperability
b.)
Internet or TCP?
c.)
Internally or Externally.
3.)
How easy to change from one to another?
WCF
1.)
WCF provides unified programming model for building service oriented
application.
2.)
One model whether communication is internal or external
3.)
Same service can be exposed over multiple protocols without effort or
switching technologies.
WCF Vs Web Services
1.)
Web services generally based on HTTP protocol and XML where as WCF based
on not only HTTP but also TCP and other protocols.
2.)
Send messages using format as SOAP in web services and within WCF send
messages using formats other than SOAP we can use
a.)
REST(Representational State Transfer)
b.)
POX(Plain Old XML)
3.)
Web service host only within web server where as WCF host on other than
web server like java server.
Different way create WCF Sever and WCF Client
WCF Service-Server
1.)
Develop using VS2010 and deploy on IIS
2.)
Deploying on WAS(Windows Activation Service)
3.)
Self host
a.)
Console Application
b.)
Windows Application/WPF Application
c.)
Web Service.
WCF Client
1.)
Using VS2010 “Add Service Reference”
2.)
Using SVCutil.exe
3.)
Custom Program(our own ways)
How TO CREATE WCF SERVICE IN CONSOLE APPLICATION
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace Myownwcfserver
{
[ServiceContract]
public interface IMyownWCFservice
{
[OperationContract]
string
SayHello(string name);
[OperationContract]
int
square(int value);
[OperationContract]
int
Add(int a, int
b);
}
public class MyownWCFservice
: IMyownWCFservice
{
public string SayHello(string
name)
{
return
"Hello " + name;
}
public int square(int value)
{
return
value * value;
}
public int Add(int a, int b)
{
return
a + b;
}
}
class Program
{
static void Main(string[]
args)
{
//create
my Host
ServiceHost
MyWCFhost = new ServiceHost(typeof(MyownWCFservice),
new Uri[] { new Uri("http://localhost:1059") });
//cretate
end point
MyWCFhost.AddServiceEndpoint(typeof(IMyownWCFservice),new BasicHttpBinding(),"myownwcfathhtp");
//add the
metadata behaviour for clint understand particular service
ServiceMetadataBehavior
smb=new ServiceMetadataBehavior
();
smb.HttpGetEnabled=true;
//add the
behaviour to my host
MyWCFhost.Description.Behaviors.Add(smb);
//open
the host
MyWCFhost.Open();
//write
some service activation messages
Console.WriteLine("my own service is running ");
Console.WriteLine("");
Console.WriteLine("press any keys to shotdown the service");
Console.ReadKey();
//close
the host
MyWCFhost.Close();
}
}
}
No comments:
Post a Comment