2015年1月14日 星期三

ASP.NET Web Service using Visual Studio Ultimate 2015 with C#

This article introduce 1. how to create a very simple web service and 2. how to create ASP.NET web page to call the web service.

My Environment: Windows Server 2012 R2 and Visual Studio Ultimate 2015 Preview
You can use Windows 2008 R2 or Windows 7 and Visual Studio 2012 or Visual Studio 2010 to get the same result

Part 1: how to create a very simple web service

1. File > New > Web Site

2. Select Visual C# and ASP.NET Empty Web Site

3. Solution Explorer shows only Web.config. Right clicks the website > Add > Add New Item

4.  Select Web Services (ASMX) > Add

5. The web service named WebService.asmx and WebServices.cs files are created. The content of the asmx file shows the code behind is WebServices.cs. We will focus on the .cs file only.


6. By default there is a HelloWorld() function automatically created for testing.


7. Copy and modify the HelloWorld() function to HelloWorldConcat(string a, string b) function as below. Notice that under the same class the web service method names must be unique, i.e. all method names must be different.

8. Press Debug button to run the test web service using Chrome (In Visual 2012/2010, the default browser is Internet Explorer). Select HelloWorldConcat > enter "It" and "works!" > Invoke, and the resultant string "It works" is contained in the XML returned text.


Part 2. how to create ASP.NET web page to call the web service

Now we are building a ASP.NET Web Forms Site to call the web service created in Part 1.

1. File > New > Web Site > Visual C# > ASP.NET Web Application > Empty

2. Right click the web application > Add > Service Reference

3. Enter the web link of the web service created in Part 1.

4. In Solution Explorer, add a Web Form (WebForm1.aspx) to the web application. In the Web Form, add 2 text box as input, 1 button as submit control, 1 label as output as below.

5. Add the control code when clicking the Button.

6. Press the Button, the output is "Seems Good~"



沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...