Friday, 3 August 2012

Sample web app that uses a WCF Service


A sample web application that consumes the my previous sample wcf service.
  • Open visual studio File --> New Web Site and name it as yours choice. It will create empty web site like this.
  • Right click on solution and select add new item.
  • Select web form and name it as CalculatorClient
  • Add this code in .aspx page.
  • Generate the button click events for above four buttons.
  • Now add the service reference to the web app as shown.
  • It leads you to a window which asking address for web reference. 
  • The address is nothing but our previous wcf service. Now run wcf service application i.e. my previous post then you will get a window with methods of service as shown then right click and copy the address as shown.
  • Then paste that address in address bar and name it as CalculatorService then click on Go next Ok as shown. 
  • Then service will be added to the solution as shown.
  • Then following lines of code automatically added to the web.config automatically the code as shown.It contains bindings and end points for the service.
  • Then write the following code in aspx.cs page.
  • Then run the application you will check all the methods of the service by using this app.
  • Note if the wcf service application stopped then our web app throws an exception.
  • If we click on stop and then use web application then it throws a error like this.
Note: Service has to be run continuously other wise we will get above error in all applications which uses the  service.


No comments:

Post a Comment