Here I will explain what WCF (windows communication foundation) is, uses of windows communication foundation and how to create and use windows communication foundation in c#.
Description:
Windows Communication Foundation (Code named Indigo) is a programming platform and runtime system for building, configuring and deploying network-distributed services. It is the latest service oriented technology; Interoperability is the fundamental characteristics of WCF. It is unified programming model provided in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.
Features
|
Web Service
|
WCF
|
Hosting
|
It can be hosted in IIS
|
It can be hosted in IIS, windows activation service, Self-hosting, Windows service
|
Programming
|
[WebService] attribute has to be added to the class
|
[ServiceContract] attribute has to be added to the class
|
Model
|
[WebMethod] attribute represents the method exposed to client
|
[OperationContract] attribute represents the method exposed to client
|
Operation
|
One-way, Request- Response are the different operations supported in web service
|
One-Way, Request-Response, Duplex are different type of operations supported in WCF
|
XML
|
System.Xml.serialization name space is used for serialization
|
System.Runtime.Serialization namespace is used for serialization
|
Encoding
|
XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
|
XML 1.0, MTOM, Binary, Custom
|
Transports
|
Can be accessed through HTTP, TCP, Custom
|
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
|
Protocols
|
Security
|
Security, Reliable messaging, Transactions
|
1) Service Class - A WCF service class implements some service as a set of methods.
2) Host Environment - A Host environment can be a Console application or a Windows Service or a Windows Forms application or IIS as in case of the normal asmx web service in .NET.
3) Endpoints - All communications with the WCF service will happen via the endpoints. The endpoint is composed of 3 parts (collectively called as ABC's of endpoint) as defines below:
Address: The endpoints specify an Address that defines where the endpoint is hosted. It’s basically url.
- "A" stands for Address: Where is the service?
- "B" stands for Binding: How can we talk to the service?
- "C" stands for Contract: What can the service do for us?
Binding
|
Description
|
BasicHttpBinding
|
Basic Web service communication. No security by default
|
WSHttpBinding
|
Web services with WS-* support. Supports transactions
|
WSDualHttpBinding
|
Web services with duplex contract and transaction support
|
WSFederationHttpBinding
|
Web services with federated security. Supports transactions
|
MsmqIntegrationBinding
|
Communication directly with MSMQ applications. Supports transactions
|
NetMsmqBinding
|
Communication between WCF applications by using queuing. Supports transactions
|
NetNamedPipeBinding
|
Communication between WCF applications on same computer. Supports duplex contracts and transactions
|
NetPeerTcpBinding
|
Communication between computers across peer-to-peer services. Supports duplex contracts
|
NetTcpBinding
|
Communication between WCF applications across computers. Supports duplex contracts and transactions
|
BasicHttpBinding
|
Basic Web service communication. No security by default
|
WSHttpBinding
|
Web services with WS-* support. Supports transactions
|
Data Contract
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="http://localhost:8090/MyFirstWcfService/SampleService.svc" binding="wsHttpBinding" contract="IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
|
|
|
|
|
[ServiceContract]
public interface IService
{
[OperationContract]
string SampleMethod(string Name);
}
|
public class Service : IService
{
public string SampleMethod(string Name)
{
return "First WCF Sample Program " + Name;
}
}
|
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
|
Create new console app from visual studio select project type as console application gives some name as you like.
|
|
|
|
|
|
static void Main(string[] args)
{
ServiceReference1.ServiceClient objService = new ServiceClient();
Console.WriteLine("Please Enter your Name");
string Message = objService.SampleMethod(Console.ReadLine());
Console.WriteLine(Message);
Console.ReadLine();
}
|
<endpoint address=" http://localhost/WCFServiceSample/Service.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
contract="ServiceReference1.IService" name="WSHttpBinding_IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
|
|
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|






Subscribe by RSS
Subscribe by Email
113 comments :
Great post bro...thanks.
Good post. Thanks for the information.
R. Ryan Avery Stone -
R. Ryan Avery Stone -
good post... u did not use Fault Contract while consuming the service.. can u please giv the more information on this...
Nice and succint
my name is babu my home town is tenali,
Good post. Thanks for the information.
i did it......thanx for d example
This is article is very easy to understand.Thanks for Sharing.(4m Kadapa)
This is very easily understandable for WCF begineers. Thanks
Rajesh
Good Sample
just a rubbish question.. in Interface u named method as Welcome & in service you say SampleMethod.. wont this cause a compile error....or WCF can handle this... if yes then do we have to write something in .config file for it?... please clarify
Online video streaming from webcam is possible in wcf
Good post it is easy understandable...Thanks alot...(4m RAMU Hyderabad)
Mohan babu good !
Very nice article especially for beginners.Looking ahead with more and more...
sir
i have some problem in user control, like i have 1 Usercontrol Having Text Box(as will as textChange event) and 1 aspx Page whre we use this usercontrol.in this page 1 Gridview .i wana to filter this gridview when any value entered on Usercontrol textbox, bind this gridview on TextChange Event of usercontrol.plz help me. send me any Ans at -sandeep.mca008@gmail.com,sandeepsharma264@gmail.com
thanks in advance
good article for beginners..
Thanks bro !! Very good Tutorial
The code in your Service.cs is not quite correct. The method name should be Welcome as it should be implementing the method defined in the IService interface else it won't compile.
thanks suresh for sharing your knowledge
rahul M
Thanks for the good Article on WCF
Great post for beginners to know what and how WCF works ..,thanks you so much ..,
thanks for this post...its very helpfull and easy.
Hi Suresh,
I'm developing application in android, now i need to develop the wfs service in .net 2010 in such away that the values entered and submitted in android application has to be stored in sql server 2008. So plase could you help me.
thanking you.
is this above method describes all about self hosting?if yes, can you give me some contents regarding IIS hosting pls?
@deva..
it's IIS hosting only not self hosting please check the post
Hi Suresh i like your blog a lot. I need some more examples on WCF where we can insert, edit, update and delete data using Sql from asp.net
Thank your for this resource. I m trying start a wcf service for a long time. but this resource really help me very much. now i can do any wcf programming.
Hi Suresh,
You blog is very informative and easy to understand.Thanks for such a useful site.
I have one question about difference b/w windows and webforms?please clarify.....
suresh.. u are awesome..!! I like ur blog. Me too have the one but some what different.
This is Santhosh
Moreover it is an structure to create Service focused programs under microsoft foundation preparing both concept and rpc design of programming.Through this we can obtain optimization platform through binary as well as start standards based marketing and sales communications.
Yes that was really helpfull :)
great post. thanks. http://prasadaknair.blogspot.com
Awesome post dear!!!!!!!!
thnks a lot for giving the basic details about wcf
Pls post article for other . net topics
like WPF, Silver light, LINQ, WFF
I am liking your blog bcuz of content quality that is simple and understandable [minimum content but describe much more in proper way] for a beginner
Very helpfull for beginners
Very informative Artical..
Thanks,
Kajal N
hai sir,
his is rajesh how to used in piechart in asp.net connect to database using dynamically.please send me my mail sir,,,vuda.rajesh59@gmail.com
Hello Suresh can u post some topics regarding Mobile Apps using .Net
Great post Bro. Easy to understand the concepts.
Good article. It helps me a lot in learning WCF..
Thank
good
great
Thanks. Done my 1st WCF example by this
good post, thanks..
Great article Suresh, well written.. Thanks
http://www.migpeg.com
nice,
hello suresh ,I have one doubt,iam create service then iam adding refrence to consoleapplication , i didnt find' Addservicerefrence' can you help me where i can add
If you right click the Project in VS you ll see Add service reference or you can use Proxy(SVCUTIL) to create the same
This is a Very simple way to learn WCF service.
Thanks for this post.
thanku
Please Upload File Upload With Percentage Progress Bar In Asp.net Please Upload It. I Need It Very Much. Thank You
this is a best example for wcf
hi suresh,nice article.try to post more advanced details reg wcf
Thanks for the good Article on WCF
this is not a standard Process to create a WCF service
hello..
can u help me how to do online video streaming via webcam in asp.net..?
Simply and very good explanation for beginners.
nice..
This link is good..
Cud u provide any other link to explain more abt WCF?
nice tutorial
Thanks man..
Nice Article. In WSHttpBinding : Web services with WS-* support. Supports transactions, could you please let me know what do you mean by WS-*?
This is Ashok here from Bengaluru.
Thanks for this post. Simple and informative. It helps me a lot.
Thanks,
AL
its a very nice post for beginners........
Hi Suresh ,
Really this is great posting for all beginners.
Thanks a lot !!!
Rajendra
ffdfff
Very informative blog.... thanks
hum yeh tutorial padh kar khush huye
good one
very nice tutorial dude
Cool Man..
I read your articles regarding web services and now read WCF Article its awesome yar..
Too much help full for beginners...
Thank you so much
Awesome bhava..
-killerBapu
Hi dis is lakshmi.good post and very useful and thanks.
its very nice and useful one
Hi Suresh, After writing the methods in iservice and service classes when i build the application it is showing the error as
"Error 1 'Service' does not implement interface member 'IService.Welcome(string)' C:\Users\muralikrishna\Documents\Visual Studio 2008\WebSites\myWCF\App_Code\Service.cs 9 14 C:\...\myWCF\
"
Why like that?
Hi iam Geting an error 'Service' does not implement interface member 'IService.Welcome(string)'
how to create Asp.net application using wcf service in Mtom
Hi suresh,
IService.cs
string Welcome(string Name);
Service.cs
public string SampleMethod(string Name)
please change the method name in IService.cs
Welcome(string Name) to SampleMethod(string Name)
or
SampleMethod(string Name) to Welcome(string Name)
Sir:>>
How to actually work MVC Architecture in asp.net ?
How to create View,Controller and Model...
Very nice and simple to understand
-Vijay
very useful..
Can you pls tell us about widget...thanx in advance
Nice aritical
Hi Sir
Nice Article
There is an error in above example.In Iservice.cs the [OperationContract] has name 'Welcome' and in Service.cs while implementing it ,bymistakely 'SampleMethod' name is used(instead of 'Welcome').Please edit it otherwise it will give error as : 'Service' does not implement interface member 'IService.Welcome(string)'
Hello sir I have read your blog and beginner to WCF. I have wcf web service so service and client on the same windows machine ...But whenever I call the service it gives an error like this
"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'."
Please help me and figure out what to do
very useful for beginners
This is very easily understandable for WCF begineers. Thanks
Really Its Nice Suresh. I had done my first WCF program using your example. Thanks
Great Article for beginners ! Appreciated your efforts !
Thnx Sir, this is so gud example of WCF technology.
Great post bro...thanks.
Hi,
The type 'WcfService1.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I am getting the above error.. Could you help me out..
g8
xlent...
you are doing a great job....keep it up.:)
sir.... plz. send the chat code on your site ...
plz sir......
thankssss you.......
very nice article on wcf..i got clear understanding about WCF..this site helping lot.
Thank u so much sir.
-
Shanth
Bangalore
Very good Site for Asp.Net
Sarika
nice one
Hi Sir
This is Santosh Kumar Chhotaray working in Asp.Net and C#. I want some tutorial in WCF. Please post some tutorial in WCF. Or mail me On hellosantoshchhotaray@gmail.com
Sir Please give one link for Android application(Hello world)
this is gooddfdfdfdfdfdfdf
qwqwqqw
weweew
awesome suresh sir lot of thanks
Regards
Rajkumar Chavan
Very nice article bro.
Very concise and well written. Well done mate!
Thanks it really works....
good article ...its really helpful
its really help me lot
Nice One Ya Brother