Click here to Skip to main content
Click here to Skip to main content

How to invoke a Web Service from a Stored Procedure

, 26 Jul 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

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.

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.

Step 4 

Then publish the web service on our IIS Web Server

Step 5 

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

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.

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.

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.

Step 9  

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

Step 10   

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

Step 11    

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


Look at the comparison and noticed that the same result.


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
Follow on   Twitter

Comments and Discussions

GeneralMy vote of 5 Pinmembermfp@novosoft.eu18-Mar-15 6:27 
GeneralMy vote of 5 PinmemberHumayun Kabir Mamun1-Mar-15 20:38 
QuestionNull value Return from SP [modified] Pinprofessionalmudgilsks4-Dec-14 4:17 
AnswerRe: Null value Return from SP Pinmemberrollypsp15-Jan-15 10:01 
QuestionWill this work in SQL 2005? PinmemberMember 1073592613-Oct-14 21:01 
QuestionGetting Null Response PinprofessionalAshish Kumar kansal18-Sep-14 22:38 
AnswerRe: Getting Null Response PinmemberOmar Frometa19-Sep-14 3:21 
GeneralMy vote of 5 PinmemberMladen Borojevic21-Aug-14 22:50 
QuestionMy Vote of 5* PinmemberMas1112-Mar-14 21:26 
QuestionNeed how to call WCF Service from strored procedure. Pinmembertosukum22-Dec-13 21:26 
QuestionCustom Soap Headers Pinmemberalemos11-Dec-13 4:12 
QuestionReturing Null Pinmembervijay kumar bollu29-Aug-13 20:27 
QuestionGetting a null response. PinmemberPulkitGulati14-Jul-13 18:04 
AnswerRe: Getting a null response. Pinmemberkhader abdul21-Aug-13 0:24 
GeneralRe: Getting a null response. PinmemberJohn Giblin31-Mar-15 5:14 
GeneralMy vote of 5 PinmemberShrikant21927-Jun-13 1:18 
GeneralMy vote of 5 Pinmemberprosthor30-May-13 2:53 
GeneralMy vote of 5 PinmemberSheikh Muhammad Haris26-Feb-13 22:39 
QuestionError Pinmemberwalder gonzalez27-Dec-12 11:52 
GeneralMy vote of 2 [modified] PinmemberEric Lapouge21-Nov-12 7:43 
GeneralMy vote of 5 PinmemberSperneder Patrick31-Oct-12 6:43 
QuestionExcellent PinmemberMusthafa (Member 379898)21-Oct-12 17:26 
GeneralMy vote of 5 PinmemberMihai MOGA8-Aug-12 6:45 
GeneralMy vote of 5 PinmvpKanasz Robert5-Aug-12 10:55 
GeneralMy vote of 5 PinmemberMonjurul Habib31-Jul-12 8:48 
GeneralMy vote of 5 PinmemberAnurag Gandhi30-Jul-12 6:34 
GeneralMy vote of 5 Pinmemberprelate28-Jul-12 9:12 
GeneralMy vote of 5 Pinmemberhahoang61199027-Jul-12 20:13 
GeneralMy vote of 4 PinmemberChristian Amado27-Jul-12 12:57 
Useful. Thanks.
GeneralThanks & Question Pinmemberii_noname_ii27-Jul-12 2:55 
GeneralRe: Thanks & Question Pinmemberii_noname_ii27-Jul-12 3:00 
GeneralRe: Thanks & Question PinmvpSacha Barber28-Jul-12 20:08 
GeneralRe: Thanks & Question PinmemberAnkur\m/31-Jul-12 23:37 
GeneralRe: Thanks & Question PinmemberJan Steyn31-Jul-12 23:46 
GeneralMy vote of 5 PinmemberIsmailLunat26-Jul-12 21:50 
GeneralNice Pinmembersund7wells26-Jul-12 19:51 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 26 Jul 2012
Article Copyright 2012 by Omar Frometa
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid