WCF service

 

1)create new project WFC service library

2)change type from to string in !service1 and service1

3)add new project to solution as Console Application

4)add reference to console application of wcf class library

5)add this code to console application 

using (ServiceHost host = new ServiceHost(typeof(Conservice.Program)))

            {

                host.Open();

                Console.WriteLine("Host Started @" +DateTime.Now.ToString());

                Console.ReadLine();

            }

6)add this code to app.config file of conservice

<system.serviceModel>

<services>

<service name="Conservice.Conservice" behaviorConfiguration="mexbehaviour">

<endpoint address="Conservice" binding="basicHttpBinding" contract="Conservice.IConService"></endpoint>

<endpoint address="Conservice" binding="netTcpBinding" contract="Conservice.IConService"></endpoint>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

<host>

<baseAddresses>

<add baseAddress="http://localhost:8085"/>

<add baseAddress="http://localhost:8733/Design_Time_Addresses/wcfservice/Service1/"/>

</baseAddresses>

</host>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="mexbehaviour">

<serviceMetadata httpGetEnabled="true"></serviceMetadata>

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

7)set conservice as startup project and test run

8)add asp.net webapp to solution and add a web page

9)give service reference to asp.net web app

10) design the web page (add textbox button and label)

11)add this code to button click

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();

            string returnString;

            returnString = client.GetData(TextBox1.Text);

            Response.Write(returnString);

12) set asp.net webapp as startup project and test

Comments