To Create and Host WCF Application in IIS Server.

Venkatesh
Posted by in WCF category on for Beginner level | Views : 9371 red flag
Rating: 5 out of 5  
 4 vote(s)

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…….

Page copy protected against web site content infringement by Copyscape

About the Author

Venkatesh
Full Name: venkatesh ponna
Member Level: Starter
Member Status: Member
Member Since: 6/24/2010 1:38:37 AM
Country: India

http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Posted by: Kullayappa on: 6/25/2010
Good work

Login to post response

Comment using Facebook(Author doesn't get notification)