using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;[ServiceContract]public interface IMyService{ [OperationContract] string HelloWorld(string name);}
using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;public class MyService : IMyService{ #region IMyService Members public string HelloWorld(string name) { return "Hello " + name; } #endregion}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> Enter User name <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Test WCF Service" onclick="Button1_Click" /><br /> <asp:Label ID="lblResult" runat="server"></asp:Label> </div> </form></body></html>
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { lblResult.Text = ""; } protected void Button1_Click(object sender, EventArgs e) { //Create instance for WCF Service class WCFRef.MyServiceClient obj = new WCFRef.MyServiceClient(); //Using instance call WCF service method and get back return string bind in the label lblResult.Text = obj.HelloWorld(TextBox1.Text); }}