How To Create A Web Service Project In .NET Using Visual Studio

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. namespace WebServiceProject
  7. {
  8. /// <summary>
  9. /// Summary description for WebService
  10. /// </summary>
  11. [WebService(Namespace = “http://tempuri.org/")]
  12. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  13. [System.ComponentModel.ToolboxItem(false)]
  14. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  15. // [System.Web.Script.Services.ScriptService]
  16. public class WebService : System.Web.Services.WebService
  17. {
  18. [WebMethod]
  19. public string HelloWorld()
  20. {
  21. return “Hello World”;
  22. }
  23. [WebMethod]
  24. public int Add(List<int> listInt)
  25. {
  26. int result = 0;
  27. for(int i =0; i< listInt.Count; i++)
  28. {
  29. result = result + listInt[i];
  30. }
  31. return result;
  32. }
  33. }
  34. }
  1. <%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”WebForm.aspx.cs” Inherits=”WebServiceProject.WebForm” %>
  2. <!DOCTYPE html>
  3. <html xmlns=”http://www.w3.org/1999/xhtml">
  4. <head runat=”server”>
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id=”form1" runat=”server”>
  9. <div>
  10. <asp:Button ID=”Button1" runat=”server” Text=”Button” OnClick=”Button1_Click” style=”height: 26px” /><asp:Label ID=”Label1" runat=”server” Text=”Label”></asp:Label>
  11. </div>
  12. </form>
  13. </body>
  14. </html>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using WebServiceProject.ServiceReference1;
  8. namespace WebServiceProject
  9. {
  10. public partial class WebForm : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. }
  15. protected void Button1_Click(object sender, EventArgs e)
  16. {
  17. WebService webService = new WebService();
  18. List<int> lstIntegers = new List<int> { 5, 6, 7 };
  19. Label1.Text = “Output of WebService: “ +webService.Add(lstIntegers).ToString();
  20. }
  21. }
  22. }

--

--

--

mesameergaikwad site It’s a blog that provides free source code ( using jQuery, HTML, CSS, SVG, JavaScript ) for our projects freely download source code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Easy Intro to N + 1 Queries in Ruby on Rails

Steaming audio in Flutter with Just Audio

Working with OpenShift: Operator, SCC and RBAC

Hard Sprint Commitments Create a Toxic Work Culture

Weekend Breaks from Coding

Dask for Python and Machine Learning

Periodic auto backup a Google sheet

7 Advanced Projects to Improve Your Programming Skills

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sameer Gaikwad

Sameer Gaikwad

mesameergaikwad site It’s a blog that provides free source code ( using jQuery, HTML, CSS, SVG, JavaScript ) for our projects freely download source code

More from Medium

Creating a Web Service for a Login Page

Mix Authentication (Win + Anonymous) in ASP.NET MVC

How to Upload Your Code to GitHub Using GitHub Desktop

How to build a REST API with ASP.NET Web API