SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
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.

Más contenido relacionado

Similar a Web services in asp.net

Windows Communication Foundation (WCF) programming using Visual Studio
Windows Communication Foundation (WCF) programming using Visual StudioWindows Communication Foundation (WCF) programming using Visual Studio
Windows Communication Foundation (WCF) programming using Visual StudioDharma Raju
 
Cis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry universityCis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry universitylhkslkdh89009
 
Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7helpido9
 
Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxhanneloremccaffery
 
Lecture2 interactive-start
Lecture2 interactive-startLecture2 interactive-start
Lecture2 interactive-startDennis Seidel
 
Build your first rpa bot using IBM RPA automation
Build your first rpa bot using IBM RPA automationBuild your first rpa bot using IBM RPA automation
Build your first rpa bot using IBM RPA automationWinton Winton
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web MahmoudOHassouna
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2Amit Sharma
 
windows azure cloud services - Lab Manual
windows azure cloud services - Lab Manualwindows azure cloud services - Lab Manual
windows azure cloud services - Lab ManualArun Kumar
 
Creating & consuming simple web service
Creating & consuming simple web serviceCreating & consuming simple web service
Creating & consuming simple web serviceAbhijit B.
 
Installing Process Oracle 10g Database Software on Windows 10
Installing Process Oracle 10g Database Software on Windows 10Installing Process Oracle 10g Database Software on Windows 10
Installing Process Oracle 10g Database Software on Windows 10Azharul Islam Shopon
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivAmit Sharma
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivAmit Sharma
 
GigaSpaces CCF Quick Tour - 2.3.6
GigaSpaces CCF Quick Tour - 2.3.6GigaSpaces CCF Quick Tour - 2.3.6
GigaSpaces CCF Quick Tour - 2.3.6Shay Hassidim
 
How to Migrate IIS Website to Another Server.pdf
How to Migrate IIS Website to Another Server.pdfHow to Migrate IIS Website to Another Server.pdf
How to Migrate IIS Website to Another Server.pdfHost It Smart
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletMitchinson
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
Details Description of Load Runner Recording option
Details Description of  Load Runner Recording optionDetails Description of  Load Runner Recording option
Details Description of Load Runner Recording optionSanchita Singha
 

Similar a Web services in asp.net (20)

Windows Communication Foundation (WCF) programming using Visual Studio
Windows Communication Foundation (WCF) programming using Visual StudioWindows Communication Foundation (WCF) programming using Visual Studio
Windows Communication Foundation (WCF) programming using Visual Studio
 
Cis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry universityCis407 a ilab 1 web application development devry university
Cis407 a ilab 1 web application development devry university
 
Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7
 
Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docx
 
Lecture2 interactive-start
Lecture2 interactive-startLecture2 interactive-start
Lecture2 interactive-start
 
Build your first rpa bot using IBM RPA automation
Build your first rpa bot using IBM RPA automationBuild your first rpa bot using IBM RPA automation
Build your first rpa bot using IBM RPA automation
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2
 
windows azure cloud services - Lab Manual
windows azure cloud services - Lab Manualwindows azure cloud services - Lab Manual
windows azure cloud services - Lab Manual
 
Creating & consuming simple web service
Creating & consuming simple web serviceCreating & consuming simple web service
Creating & consuming simple web service
 
Installing Process Oracle 10g Database Software on Windows 10
Installing Process Oracle 10g Database Software on Windows 10Installing Process Oracle 10g Database Software on Windows 10
Installing Process Oracle 10g Database Software on Windows 10
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
GigaSpaces CCF Quick Tour - 2.3.6
GigaSpaces CCF Quick Tour - 2.3.6GigaSpaces CCF Quick Tour - 2.3.6
GigaSpaces CCF Quick Tour - 2.3.6
 
How to Migrate IIS Website to Another Server.pdf
How to Migrate IIS Website to Another Server.pdfHow to Migrate IIS Website to Another Server.pdf
How to Migrate IIS Website to Another Server.pdf
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Details Description of Load Runner Recording option
Details Description of  Load Runner Recording optionDetails Description of  Load Runner Recording option
Details Description of Load Runner Recording option
 

Último

Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringPrakhyath Rai
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...CloudMetic
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Gáspár Nagy
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...OnePlan Solutions
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024Shane Coughlan
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024MulesoftMunichMeetup
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio, Inc.
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 

Último (20)

Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
Salesforce Introduced Zero Copy Partner Network to Simplify the Process of In...
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 

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. dharma.rmm@gmail.com 15th Apr 2020.