SlideShare a Scribd company logo
2
Most read
Web Services in Asp.net (VB Code)
1. Run Visual Web Developer / Visual Studio (I am using Visual Studio 2013)
2. Click on New project.
3. From the left-side pane, choose Templates → Visual Basic → Web
4. Choose Asp.net web application from the central window. Give some file name and
choose your convenient drive and a folder.
5. Click OK to proceed.
6. Choose Empty from ‘Select a Template’ screen.
Stage 1: Creating Web Service
1. Right Click on Project (from the Solution Explorer). Select Add→New Item →
Web Service (ASMX)
2. Give some name for this webservice (or retain the default name suggested by
your system). I have retained the default name ie. WebService1.asmx. Click on
Add button. The system switch over to the screen with the following codes.
3. Now, concentrate on the section starting with the line <WebMethod()>_
4. Here you can write your own codes. Now, let us try ourselves.
5. Let us add two methods in this section to add and subtract two numbers.
a. First remove the lines Public Function ….. End Function
b. Add the following lines as shown below (I have added two methods – add
and subtract). See the code below.
6. Now, you can check the above codes for any errors. For this purpose, click on
Build → Build Solution.
7. You can see message is 1 succeeded, 0 failed ….. This shows that the new codes
added is OK.
8. You can also run your web service code in a browser. For this, right click on the
screen and choose ‘Run to Cursor’. The program runs in your default browser.
9. Notice our two methods (functions) namely, add and subtract are appearing on
the screen. Click on them and supply two numeric values to test whether these
functions are working properly or not.
10. That’s it. We have created a web service with two functions – one for addition of
two numbers and another for subtracting two numbers.
Stage 2: Importing this webservice to our website
Now, let us see how to import the Webservice created in the above to our website.
1. Stop the debugging of the above webservice, if any by pressing Shift+F5 or clicking
on the stop debugging button as shown below
2. Right click on the Project (Visible in the Solution Explorer window) → Add → Service
Reference.
3. Click on the Discover button
4. You can see WebService1.asmx appears on the Services window.
5. Expand all the nodes to view Add and Subtract functions in the Operations Window.
6. Press Ok to save.
Stage 3: Consuming the WebService from a web page
Now, let us see, how to consume (or use in a web page)
1. Right click on Project → Add → New Item → Web Form
2. Change to design mode.
3. Add Two Text Boxes, Two Labels and a Button as shown below.
4. Double click on the Button. Add codes for the Button1 click event.
5. Save the webpage. Go back to design mode. View your webpage in a browser (ie.
Right click on your webpage and select View in Browser option).
Note: When you are in debug mode, you cannot view the webpage in a browser. For
this purpose, close the debug mode by pressing Shift+F5 buttons)
That’s it. You have created a webservice and a webpage which consume it. I have used
Visual Basic codes for the above. It can also be developed using C# with few modifications.
Webservices with Database Connectivity:
I have given below code required to connect a back-end database (in this case, I have used MS SQL
Server) from a web services.
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following
line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
<WebMethod()> _
Public Function connect(vcode as string ) As String
Dim connection As SqlConnection
Dim command1 As SqlCommand
Dim dr1 As SqlDataReader
Dim sql1, sql2 As String
connection = New SqlConnection("Data Source=xxxx;Initial Catalog=xxxx;User
ID=xxxx;Password=xxxx")
connection.Open()
Dim vcode as As String
sql1 = "select VendorName from vendorMaster where vendorCode='" + vcode + "'"
command1 = New SqlCommand(sql1, connection)
dr1 = command1.ExecuteReader
While dr1.Read
Return (dr1("VendorName").ToString)
End While
End Function
End Class
--------------------------------
Happy coding.
- BK Dharmaraju, Bangalore, India.
dharma.rmm@gmail.com
15th
Apr 2020.

More Related Content

Similar to Web services in asp.net (20)

PDF
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
PPT
Web services intro.
Ranbeer Yadav
 
DOCX
KO on Web Services
Manjunatha RK
 
PDF
Windows Communication Foundation (WCF) programming using Visual Studio
Dharma Raju
 
PPT
Bespoke Digital Media - Web
bespokedigitalmedia
 
PPT
Web Services With Delphi, Sep, 2008
Black Knight Financial Services
 
PPTX
Parallelminds.asp.net web service
parallelminder
 
PPTX
Creating & consuming simple web service
Abhijit B.
 
PPTX
UNIT 3 web iiiBCA.pptx
VijayKumarLokanadam
 
PPT
Test
rebelvenky1
 
PPTX
Web services
aspnet123
 
PPT
Synapse india dotnet development web approch
Synapseindiappsdevelopment
 
PPT
Deploy and Publish Web Service
pradeepfdo
 
PPT
Consume wsa
mahe797
 
PPT
Espositoajaxremote 1210732828647866-8
Sopheak Sem
 
PPT
.Net Project Portfolio for Roger Loving
rloving10
 
PPT
Working with WebServices.ppt
pepep15
 
PDF
6 Months Dotnet internship in Noida
Tech Mentro
 
PPTX
Development of Web Services for Android Applications
Md Ashraful Haque
 
PPT
Synapse india reviews sharing chapter 23 – asp.net-part2
Synapseindiappsdevelopment
 
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
Web services intro.
Ranbeer Yadav
 
KO on Web Services
Manjunatha RK
 
Windows Communication Foundation (WCF) programming using Visual Studio
Dharma Raju
 
Bespoke Digital Media - Web
bespokedigitalmedia
 
Web Services With Delphi, Sep, 2008
Black Knight Financial Services
 
Parallelminds.asp.net web service
parallelminder
 
Creating & consuming simple web service
Abhijit B.
 
UNIT 3 web iiiBCA.pptx
VijayKumarLokanadam
 
Web services
aspnet123
 
Synapse india dotnet development web approch
Synapseindiappsdevelopment
 
Deploy and Publish Web Service
pradeepfdo
 
Consume wsa
mahe797
 
Espositoajaxremote 1210732828647866-8
Sopheak Sem
 
.Net Project Portfolio for Roger Loving
rloving10
 
Working with WebServices.ppt
pepep15
 
6 Months Dotnet internship in Noida
Tech Mentro
 
Development of Web Services for Android Applications
Md Ashraful Haque
 
Synapse india reviews sharing chapter 23 – asp.net-part2
Synapseindiappsdevelopment
 

Recently uploaded (20)

PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Ad

Web services in asp.net

  • 1. Web Services in Asp.net (VB Code) 1. Run Visual Web Developer / Visual Studio (I am using Visual Studio 2013) 2. Click on New project. 3. From the left-side pane, choose Templates → Visual Basic → Web 4. Choose Asp.net web application from the central window. Give some file name and choose your convenient drive and a folder. 5. Click OK to proceed. 6. Choose Empty from ‘Select a Template’ screen. Stage 1: Creating Web Service 1. Right Click on Project (from the Solution Explorer). Select Add→New Item → Web Service (ASMX)
  • 2. 2. Give some name for this webservice (or retain the default name suggested by your system). I have retained the default name ie. WebService1.asmx. Click on Add button. The system switch over to the screen with the following codes. 3. Now, concentrate on the section starting with the line <WebMethod()>_ 4. Here you can write your own codes. Now, let us try ourselves. 5. Let us add two methods in this section to add and subtract two numbers. a. First remove the lines Public Function ….. End Function b. Add the following lines as shown below (I have added two methods – add and subtract). See the code below.
  • 3. 6. Now, you can check the above codes for any errors. For this purpose, click on Build → Build Solution. 7. You can see message is 1 succeeded, 0 failed ….. This shows that the new codes added is OK. 8. You can also run your web service code in a browser. For this, right click on the screen and choose ‘Run to Cursor’. The program runs in your default browser. 9. Notice our two methods (functions) namely, add and subtract are appearing on the screen. Click on them and supply two numeric values to test whether these functions are working properly or not. 10. That’s it. We have created a web service with two functions – one for addition of two numbers and another for subtracting two numbers. Stage 2: Importing this webservice to our website Now, let us see how to import the Webservice created in the above to our website. 1. Stop the debugging of the above webservice, if any by pressing Shift+F5 or clicking on the stop debugging button as shown below
  • 4. 2. Right click on the Project (Visible in the Solution Explorer window) → Add → Service Reference. 3. Click on the Discover button 4. You can see WebService1.asmx appears on the Services window. 5. Expand all the nodes to view Add and Subtract functions in the Operations Window.
  • 5. 6. Press Ok to save. Stage 3: Consuming the WebService from a web page Now, let us see, how to consume (or use in a web page) 1. Right click on Project → Add → New Item → Web Form 2. Change to design mode. 3. Add Two Text Boxes, Two Labels and a Button as shown below. 4. Double click on the Button. Add codes for the Button1 click event. 5. Save the webpage. Go back to design mode. View your webpage in a browser (ie. Right click on your webpage and select View in Browser option). Note: When you are in debug mode, you cannot view the webpage in a browser. For this purpose, close the debug mode by pressing Shift+F5 buttons) That’s it. You have created a webservice and a webpage which consume it. I have used Visual Basic codes for the above. It can also be developed using C# with few modifications. Webservices with Database Connectivity: I have given below code required to connect a back-end database (in this case, I have used MS SQL Server) from a web services.
  • 6. Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data.SqlClient ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. ' <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Public Class WebService Inherits System.Web.Services.WebService <WebMethod()> _ Public Function HelloWorld() As String Return "Hello World" End Function <WebMethod()> _ Public Function connect(vcode as string ) As String Dim connection As SqlConnection Dim command1 As SqlCommand Dim dr1 As SqlDataReader Dim sql1, sql2 As String connection = New SqlConnection("Data Source=xxxx;Initial Catalog=xxxx;User ID=xxxx;Password=xxxx") connection.Open()
  • 7. Dim vcode as As String sql1 = "select VendorName from vendorMaster where vendorCode='" + vcode + "'" command1 = New SqlCommand(sql1, connection) dr1 = command1.ExecuteReader While dr1.Read Return (dr1("VendorName").ToString) End While End Function End Class -------------------------------- Happy coding. - BK Dharmaraju, Bangalore, India. [email protected] 15th Apr 2020.