What is WCF ?
Windows Communication foundation API allows to build distributed architecture in such manner that once created service code can be utilize by the in-house application which using tcp/ip to communicate, web application using http protocol to communicate to web services, application using msmq. WCF Services also works with the application developed other than .net framework.
Create WCF Service
Follow the below listed step to create Service
Step 1:
Create service from the Visual Studio select the go to c# or vb than select project type WCF Service library or WCf service website project template.
the first one create the *.dll and app.config file for after the compilation which you can than use in your host application and expose the service to clients.
the second one create the project with the proper web.config file and *.svc file which is get hosted on IIS via virtual directly and service get explose to client via HTTP protocol. so by that service can not be expose to tcp client. The benefit of this option is no need to create host application you can directly host it on iis via virtual directory.
For this discussion first I am creating WCF service library and than I am going to discuss about iis deployment also.
Step 2:
Create contract by specifing proper attributes. This contract tells the client what are the method get expose by the service and custom type expose by the service. You can decorate your contract by the list of attribute in System.ServiceModel namespace.
you can create you own files or after selecting proper project type its create two files for you Iservcie.cs and Service.cs. If you are going to create your own files its recommanded that you can create you interface and implement it in your class.
[ServiceContract] - defines the interface participate in provided service.
[OperationContract] - defines the method going to be expose by the service.
[DataMember] - defines the property expose via service.
[DataContract] - defines the custom data type expose via service.
After you done with the creation of the web service you code should look as below
Library app.config file
This file contains infomation about the metadata exchange defines endpoint of metadata. its also contains information about the endpoints where client talk with service.
Endpoints are ABC means Address, Binding and Contract. as you see in above config file service expose for tcp communication by following line
Binding details : http://www.c-sharpcorner.com/UploadFile/pjthesedays/bindwcf05032009012251AM/bindwcf.aspx
IService.Cs file
Service.cs
Hosting WCF Service
- Self Host
- IIS hosting
- Windows service
- WAS
Self hosting
Step 1:
Create new project >> Class Library >> name this project as Host
Step 2:
Add referance to the host application
Right click on Referance >> Add Referance
Step 3:
After adding referance to the host application to expose webservice for client to consume
as you see below line of the code create the object of the host and which is of type Service1 Which we created in the WCF Service library project
as you can see we used using block over so that it depose host object when we close application.
Step 4:
to start the service to hadle request coming form the client of ther service you need to call open method
and to stop receiving request you need to call close method
Host.cs
IIS hosting
- To host same WCF library in your application create WCF Web application project using WCF web application template as we discuss in start.
- Delete the files created in the IService.cs and Service.cs file from App_Code folder
- Include WCF library *.dll file which we created.
- Open Service.svc file and modify the single line in it
- Change the web service WEB.Config file to to expose service to client. i.e you need to create Same element as listed above in in the app.config file of service library.
Step 1:
Create new project >> Class Library >> name this project as Client as we created Host application
If you want to consume webservice hosted in you web application start directly for the 2 step listed below.
Step 2:
Add Service Referance to the client by Right click on project >> Add Service Referance
which atomatically create the proxy files to consume web service.
or
Make use of ServiceModel Metadata Utility Tool (Svcutil.exe) the is command-line tool to generate proxy code from metadata.
svcutil /t:code http://<service_url> /out:<file_name>.cs /config:<file_name>.config
Step 3:
To send request to service form the client
So as you see in above code you need to create object of Service1Client and than you can easily call the method expose by the Service. If you want to see the auto-generated code press F12 on the Service1Client it show the proxy code to you.
Summary :
As you follow the process listed process step by step its quite easy to create, consume and host WCF Service.
Thank you! Got lot of concepts cleared after reading this article
ReplyDeleteHow to consume this WCF service using jquery
ReplyDeleteSathish - there is already article on my blog regarding consuming the WCF via Jquery you can check it....
ReplyDeleteThanks vry much for your article. Do you have an article for cross domain webservice
ReplyDeleteHola! I've been reading your web site for a long time now and finally got the bravery to go ahead and give you a shout out from Porter Texas! Just wanted to tell you keep up the good work!
ReplyDeleteAlso see my website - view
How to consume this WCF service using jquery
ReplyDeleteHello, i think that i saw you visited my website thus i got here to
ReplyDeletego back the favor?.I'm trying to in finding issues to improve my web site!I guess its good enough to make use of a few of your ideas!!
My blog post institution Johannesburg
Also see my web site > make up artist Johannesburg
Hello there, You have done a great job.
ReplyDeleteI will definitely digg it and personally recommend to my friends.
I'm confident they'll be benefited from this site.
Also visit my web blog ... cellulite Urban
I every time spent my half an hour to read this weblog's content every day along with a cup of coffee.
ReplyDeleteHere is my blog post - more info
It's amazing to visit this site and reading the views of all mates concerning this paragraph, while I am also eager of getting experience.
ReplyDeleteFeel free to visit my webpage :: vexxhost feedback
Wow, this piece of writing is pleasant, my sister is analyzing
ReplyDeletethese kinds of things, thus I am going to let know her.
Feel free to visit my web page :: visit link
Very good post. I certainly love this site. Stick with it!
ReplyDeleteCheck out my web page :: more info
Hi! I understand this is somewhat off-topic however I needed to ask.
ReplyDeleteDoes building a well-established blog like yours take a large amount of work?
I'm completely new to operating a blog but I do write in my diary everyday. I'd like to
start a blog so I can share my personal experience and feelings online.
Please let me know if you have any kind of ideas or tips for
brand new aspiring bloggers. Thankyou!
my web-site; site
Hi, of course this article is in fact pleasant and I have learned lot
ReplyDeleteof things from it on the topic of blogging. thanks.
Here is my web-site - recruitment agencies Gauteng
I'm gone to tell my little brother, that he should also pay a visit this blog on regular basis to get updated from newest reports.
ReplyDeleteAlso visit my blog post; hip to waist ratio
Just want to say your article is as surprising. The
ReplyDeleteclarity for your put up is just nice and i can assume
you are an expert in this subject. Fine together with your
permission let me to grab your feed to stay updated with coming near near
post. Thank you 1,000,000 and please carry on the rewarding work.
Look at my website Different Jewellery
For latest news you have to pay a visit internet
ReplyDeleteand on internet I found this website as a best site for most up-to-date updates.
My web blog ... windows xp registry cleaner
Hi to all,-my Samsung ML 1410 now functions fine (Home windows 8 Pro 64 little bit).
ReplyDeleteThanks a lot for that excellent Study.
My weblog: xerox phaser 8560 solid ink
Hey there to all,-my Samsung ML 1410 now functions fine
ReplyDelete(Home windows 8 Pro 64 little bit). Many thanks a great deal for that great Research.
My webpage - xerox phaser 8560mfp
If you are going for best contents like I do, just visit this site all the time as
ReplyDeleteit gives feature contents, thanks
My blog post :: best diet pills
Excellent, what a website it is! This web site presents helpful
ReplyDeletedata to us, keep it up.
my web site ... semenax
I think that is one of the such a lot significant information for me.
ReplyDeleteAnd i am glad studying your article. However want to observation on some general issues, The website style is ideal, the articles is in point of fact nice :
D. Excellent activity, cheers
Also visit my webpage :: vigrx for men
fantastic submit, very informative. I'm wondering why the other specialists of this sector don't understand this.
ReplyDeleteYou should continue your writing. I am sure, you have a great readers' base already!
My page - virility ex
Do you have a spam problem on this site; I also am a blogger,
ReplyDeleteand I was wondering your situation; we have created some nice procedures and
we are looking to swap strategies with other folks, be sure to shoot me an email if interested.
My site: human growth hormone
Hi there! I could have sworn I've visited this site before but after looking at some of the posts I realized it's new to me.
ReplyDeleteNonetheless, I'm definitely delighted I came across it and I'll be book-marking it and
checking back regularly!
my homepage ... hoodia balance
I'll right away take hold of your rss feed as I can not to find your e-mail subscription link or e-newsletter service. Do you've any?
ReplyDeletePlease let me realize so that I may subscribe.
Thanks.
Here is my web page :: thyromine
I'm not sure why but this web site is loading very slow for me. Is anyone else having this issue or is it a problem on my end? I'll
ReplyDeletecheck back later on and see if the problem still exists.
Feel free to surf to my web page :: male enhacment
sir, please send the video to my email, its fantastic.
ReplyDeleteStop by my site ... http://ateljeskogslyckan.blogspot.com/2012/04/blakulla-ja-men-da-var-det-dags-igen.html
Good post. I definitely love this site. Stick with it!
ReplyDeleteAlso visit my web page: buy genf20 plus
hp laserjet p1505 printer drivers download.
ReplyDeletemy web blog http://galilee.ezpt.kr/
I was actually shocked to go through that this partnered with a Lexmark, but I
ReplyDeleteGoogled the E210 and it looks virtually identical
to the Samsung ML-1210 ... So I suspect there are
some inter-manufacturer resemblances that I was not aware
of.
Have a look at my webpage - xerox phaser 8560 maintenance kit
Awesome issues here. I am very glad to see your article.
ReplyDeleteThank you so much and I'm taking a look forward to contact you. Will you please drop me a e-mail?
Take a look at my web site breast actives testimonials
Greetings! Very helpful advice in this particular post!
ReplyDeleteIt is the little changes which will make the biggest changes.
Many thanks for sharing!
My page; buy zetaclear
say thanks to's wonderful idea, you are better than samsung's
ReplyDeletedesigner !!!
my website xerox phaser 8560 maintenance kit
Very nice article. I definitely appreciate this site.
ReplyDeleteContinue the good work!
Feel free to visit my webpage ... provillus cheap
Hello to every body, it's my first visit of this web site; this website contains awesome and truly good stuff in favor of readers.
ReplyDeletemy web site; snorezip.herbalcurenow.com
Howdy this is kind of of off topic but I was wondering
ReplyDeleteif blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!
Also visit my blog post :: virility ex instructions
I am really inspired with your writing skills as smartly as
ReplyDeletewith the format in your weblog. Is this a paid subject matter or did you
customize it your self? Anyway keep up the excellent quality writing, it is rare to look a great blog like this one nowadays.
.
My web blog; buy genf20 plus
Hey would you mind stating which blog platform you're working with? I'm planning to start my own
ReplyDeleteblog soon but I'm having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something unique.
P.S Apologies for being off-topic but I had to ask!
Feel free to surf to my website - smoke deter
You actually make it appear really easy together with your presentation but I in finding this matter to be really something which I believe I might
ReplyDeletenever understand. It sort of feels too complex and very huge for me.
I am having a look forward for your next put up,
I'll attempt to get the hang of it!
Look into my webpage :: venaro natural pearl
Wow, fantastic blog layout! How long have you been blogging
ReplyDeletefor? you make blogging look easy. The overall look of your site
is great, as well as the content!
Also visit my web-site :: breast actives
I do accept as true with all the ideas you have presented on your post.
ReplyDeleteThey're really convincing and can definitely work. Still, the posts are too quick for novices. May just you please lengthen them a little from subsequent time? Thank you for the post.
Here is my web-site - energizery