Click here to Skip to main content
14,773,699 members
Articles » Web Development » Web Services » General
Posted 25 Jul 2012


127 bookmarked

How to invoke a Web Service from a Stored Procedure

Rate me:
Please Sign up or sign in to vote.
4.90/5 (64 votes)
26 Jul 2012CPOL
Learning how to make a call to a Web Service from a Stored Procedure.


On one occasion an old friend, was planning some applications  using NET and sockets, and needed to call a WebServices from a stored procedure.

In this article I will share this experience so that other programmers can learn to call a WebService sending parameters from a Stored Procedure. 

Step 1 

We must create our WebServices Project in Visual Studio.

Image 1

Step 2 

Then proceed to create the methods that we use in our service, in my case believe 6 methods which are:  Greet (string Param1) and expects a String as the parameter, HelloWord() does not expect any parameters, and the  Add, subtract, and Divide proliferation (Num1 int, int num2) want  two integers as parameters.

Image 2

Step 3 

Proceed to create our stored procedure that will have all the code to invoke the Web Services we have just created, as in all my articles database I use is AdventureWorks, which is the basis of test data that brings SQL Server.

Image 3

Step 4 

Then publish the web service on our IIS Web Server

Image 4

Image 5

Step 5 

We proceed to our Store Procedure Coding the data of our Web Service.

Image 6

Step 6 

In the procedure to create, we pass a parameter which is the parameter that is waiting Saludar() method, if they want to use the other methods, should create another parameter because as I mentioned above the other methods are expecting 2 parameters integer type. 

Something that is also very important when using the sp_OAMethod Stored Procedure this awaiting the POST or GET method, default almost always send POST, but if we sent this method, we can not display the XML reading generated by our Web Service, so we must use the GET method.

Image 7

Step 7 

Proceed to test our Web Service through your browser, type the address of the IIS where the published our Web Service. http://localhost/WebServices/Service1.asmx in the same show all the methods that  we created in our Web Service.

Image 8

Step 8 

Select the method that we use and invoke from our Stored Procedure, Saludar(). Then proceed to write the parameter you want to happen to the Web Service,  after this we click on Invoke.

Image 9

Step 9  

After that it will open another page in your browser, the information contained in XML and the parameter to write.

Image 10

Step 10   

We proceed to execute the stored procedure we just created to invoke our web service.

Image 11

Step 11    

After running our procedure and send our parameters we get the same result we got when we run it through your browser.

Image 12


Look at the comparison and noticed that the same result.

Image 13


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Omar Frometa
Dominican Republic Dominican Republic
MCTS - SQL Server 2008
Microsoft Certified Technology Specialist

CETEX - Exactus ERP
Exactus Technician Certificate

Comments and Discussions

QuestionGetting Null Response Pin
Member 1150562825-Jun-19 19:57
MemberMember 1150562825-Jun-19 19:57 
QuestionQuestion Pin
Member 1279921725-Jun-19 17:44
professionalMember 1279921725-Jun-19 17:44 
Questionhow can return multi values from web service and using it in stored proceduer Pin
Member 1065999230-Jul-18 5:19
MemberMember 1065999230-Jul-18 5:19 
Questionvarious parameters Pin
Member 1359649413-Mar-18 8:40
MemberMember 1359649413-Mar-18 8:40 
Questionproblem with 3parameters Pin
Member 135108818-Nov-17 10:48
MemberMember 135108818-Nov-17 10:48 
QuestionI get null value when executing this procedure Pin
Member 118599335-Jul-17 22:15
MemberMember 118599335-Jul-17 22:15 
AnswerRe: I get null value when executing this procedure Pin
Member 1359649413-Mar-18 8:59
MemberMember 1359649413-Mar-18 8:59 
QuestionGetting NULL Response Pin
Member 100213952-May-17 5:20
MemberMember 100213952-May-17 5:20 
AnswerRe: Getting NULL Response Pin
ekiran1434-May-17 20:29
Memberekiran1434-May-17 20:29 
QuestionCalling web service through stored procedure Pin
hemant bhor18-May-15 20:17
Memberhemant bhor18-May-15 20:17 
QuestionUse of User and Password in the WebServices Pin
Member 1169421915-May-15 12:39
MemberMember 1169421915-May-15 12:39 
GeneralMy vote of 5 Pin
mfp@novosoft.eu18-Mar-15 6:27
Membermfp@novosoft.eu18-Mar-15 6:27 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun1-Mar-15 20:38
MemberHumayun Kabir Mamun1-Mar-15 20:38 
QuestionNull value Return from SP Pin
mudgilsks4-Dec-14 4:17
professionalmudgilsks4-Dec-14 4:17 
AnswerRe: Null value Return from SP Pin
rollypsp15-Jan-15 10:01
Memberrollypsp15-Jan-15 10:01 
QuestionWill this work in SQL 2005? Pin
Member 1073592613-Oct-14 21:01
MemberMember 1073592613-Oct-14 21:01 
QuestionGetting Null Response Pin
Ashish Kumar kansal18-Sep-14 22:38
professionalAshish Kumar kansal18-Sep-14 22:38 
AnswerRe: Getting Null Response Pin
Omar Frometa19-Sep-14 3:21
MemberOmar Frometa19-Sep-14 3:21 
GeneralMy vote of 5 Pin
Mladen Borojevic21-Aug-14 22:50
professionalMladen Borojevic21-Aug-14 22:50 
QuestionMy Vote of 5* Pin
Mas1112-Mar-14 21:26
MemberMas1112-Mar-14 21:26 
QuestionNeed how to call WCF Service from strored procedure. Pin
tosukum22-Dec-13 21:26
Membertosukum22-Dec-13 21:26 
QuestionCustom Soap Headers Pin
alemos11-Dec-13 4:12
Memberalemos11-Dec-13 4:12 
QuestionReturing Null Pin
vijay kumar bollu29-Aug-13 20:27
Membervijay kumar bollu29-Aug-13 20:27 
QuestionGetting a null response. Pin
PulkitGulati14-Jul-13 18:04
MemberPulkitGulati14-Jul-13 18:04 
AnswerRe: Getting a null response. Pin
khader abdul21-Aug-13 0:24
Memberkhader abdul21-Aug-13 0:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.