Introduction

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.

How to invoke a Web Service from a Stored Procedure_第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 Addsubtract, and Divide proliferation (Num1 int, int num2) want  two integers as parameters.

How to invoke a Web Service from a Stored Procedure_第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.

How to invoke a Web Service from a Stored Procedure_第3张图片

Step 4 

Then publish the web service on our IIS Web Server

How to invoke a Web Service from a Stored Procedure_第4张图片

How to invoke a Web Service from a Stored Procedure_第5张图片

Step 5 

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

How to invoke a Web Service from a Stored Procedure_第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 GETmethod, 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.

How to invoke a Web Service from a Stored Procedure_第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.

How to invoke a Web Service from a Stored Procedure_第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.

Step 9  

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

How to invoke a Web Service from a Stored Procedure_第9张图片

Step 10   

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

How to invoke a Web Service from a Stored Procedure_第10张图片

Step 11    

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

How to invoke a Web Service from a Stored Procedure_第11张图片

Results    

Look at the comparison and noticed that the same result.

How to invoke a Web Service from a Stored Procedure_第12张图片