What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3248 |  Welcome, Guest!   Register  Login
Home > Articles > WCF > To Create and Host WCF Application in IIS Server.

To Create and Host WCF Application in IIS Server.

4 vote(s)
Rating: 5 out of 5
Article posted by Venkatesh on 6/24/2010 | Views: 5977 | Category: WCF | Level: Beginner red flag


To Create and Host WCF Application in IIS Server.

Introduction



To Create and Host WCF Application in IIS Server.

Go to Visual Studio 2008 --> File --> Clicks on New Website. It opens the below window



There you can select WCF Service. Specify the location that is http, here I selected the as shown fig above. and click on OK button you will get another window.



After that service.cs file will open automatically. When we creating WCF service by default some files and folders are there.

  1. App_Code Folder
  2. App_Data Folder
  3. Service.svc
  4. Web.Config file

In App_Code Folder by default two class files are generated.

  1. IService.cs
  2. Service.cs


Open service.cs file write this code

public string getname(string name)

{

return "Hello" + name;

}

next open web.config file and add path in the endpoint

endpoint address="http://localhost/WCFService/Service.svc" binding="wsHttpBinding" contract="IService">

This end point will be in Service.

Open Internet Information Service, there you select your service and click on service.svc you will get a path.






Now open visual studio 2008 command prompt type this command.

Svcutil http://localhost/WCFService/Service.svc (this is the path of WCF Service)

Using service utility we can create the proxy class and its configuration information.

You will get two output files

  1. Service.cs
  2. Output.config

Now will create sample application in asp.net

Open Solution Explorer Right click on Add Reference you will get a pop up window




In this window select System.ServiceModel click on OK button.

Next right click on Solution Explorer click on Add Service Reference; you will get a popup window




In the above window type Address of your WCF Service path click on GO button

If path exists you will get a Service that will be saved in your Solution Explorer.





Here we have to create a object of service.


Add these namespaces

using System.ServiceModel;

using ServiceReference1;

On button click event write this code


protected void btnget_Click(object sender, EventArgs e)
{
ServiceClient serv = newServiceClient();

string
val = txtboxuser.Text;
Response.Write(serv.getname(val));

}




Here Enter any name in that text box, it calls the method which written in Service.cs file and will get a result







This is the final output.

Happy Programming…….

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Latest Articles from Venkatesh
Experience:2 year(s)
Home page:http://www.dotnetfunda.com
Member since:Thursday, June 24, 2010
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Kullayappa | Posted on: 25 Jun 2010 04:41:33 AM

Good work

>> Write Response - Respond to this post and get points
Related Posts

This article will explain creation of custom binding in WCF services.

In this article, we are going to see how to host Windows service in WCF and automatically start and stop the Service by using Button click events.

WCF has introduced lot of bindings and protocols. This article will concentrate on two important protocols BasicHttpBinding and WsHttpBinding which look similar but have some huge fundamental differences. So we will first start with the difference and then we will make a small project and see how the differences look practically.

In this article we will try to understand how we can implement transactions in WCF service. So we will create two WCF services which does database transactions and then unite them in one transaction. We will first understand the 6 important steps to enable transactions in WCF services. At the end of the article we will try to force an error and see how the transaction is rolled back after the error.

In this article we will look how we can trace and debug information in WCF services. There are some ready made tracelisteners provided by WCF. The base of these ready made trace listeners is .NET trace listener. So we will first understand the basic concept of trace listener and then go through the ready made tracelisteners provided by WCF.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 10:06:03 PM