i have tried the procedure as mentioned above but i want to send some data as parameters of web service function from stored procedure to web service
Razvan Socol wrote:
Here is an example of a call to a web service using SOAP Toolkitwithin SQL
31-Jan-07
Here is an example of a call to a web service using SOAP Toolkit
within SQL Server:
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'MSSOAP.SoapClient30', @object OUT
IF @hr <> 0 GOTO errorhandler
EXEC @hr = sp_OAMethod @object, 'MSSoapInit', NULL, 'http://
ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl'
IF @hr <> 0 GOTO errorhandler
DECLARE @Name varchar(1000)
EXEC @hr = sp_OAMethod @object, 'checkVat', NULL, 'RO', 19, NULL,
NULL, @Name OUT, NULL
IF @hr <> 0 GOTO errorhandler
PRINT @name
GOTO finish
errorhandler:
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
finish:
EXEC @hr = sp_OADestroy @object
The above code should print "BUCUR OBOR SA", which is the name of the
company having the VAT code "RO19" in Romania.
However, be advised that SOAP Toolkit is no longer supported (since
April 2005) and that using the sp_OA procedures is usually tricky.
Therefore you should consider upgrading to SQL Server 2005, where you
can create a CLR stored procedure and invoke the web service using the
standard .NET calls.
Razvan
Previous Posts In This Thread:
On Tuesday, January 30, 2007 9:56 PM
ekki wrote:
Calling a web service in SQL2K
I've isntalled the SOAP Toolkit on a SQL Server 2000 box (see:
http://tinyurl.com/aw2o) and am trying to invoke a web service from a stored
procedure.
I have been successful in retrieving simple datatype values (from calls to
GetInteger and GetString) but when the returned value is not simple (call to
GetComplex) what I get is a handle I don't know what to do with... I've tried
retrieving properties on the returned object and have read through both the
SoapClient30 documentation and the OLE Automation stored procedures docs but
can't quite seem to figure it out.
Below is my web service, with the XML returned in two relevant cases, and a
working example of a stored procedure that retrieves a string value... can
anyone help?
--- Web Service
---------------------------------------------------------------
using System;
using System.Web.Services;
[WebService(Namespace="http://tcw.com/")]
public class SecurityWebService : WebService
{
[WebMethod(Description="Returns a string",EnableSession=false)]
public string GetString()
{
return "Gewurtztramminer";
}
[WebMethod(Description="Returns a given string",EnableSession=false)]
public string GetStringWithArg(string s)
{
if (s == "") s = "Gewurtztramminer";
return s;
}
}
--- Returned XML for String method call -------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tcw.com/">Gewurtztramminer</string>
--- Returned XML for Complex method call ----------------------------------
<?xml version="1.0" encoding="utf-8" ?>
- <ComplexReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tcw.com/">
<Code>Test</Code>
<Price>3</Price>
</ComplexReturn>
--- Stored Procedure
----------------------------------------------------------
if object_id('ecx') is not null
drop proc ecx
go
CREATE PROC ecx
AS
DECLARE @err int
, @sh int -- SOAP handle
, @ret varchar(8000)
, @msg varchar(32)
SELECT @msg = 'sp_OACreate'
EXEC @err = sp_OACreate 'MSSOAP.SoapClient30', @sh OUT
IF @err = 0
BEGIN
SELECT @msg = 'MSSoapInit'
EXEC @err = sp_OAMethod @sh
, 'MSSoapInit'
, NULL
, 'http://LAD1009291/SampleService.asmx?WSDL'
END
IF @err = 0
BEGIN
SELECT @msg = 'GetComplex'
EXEC @err = sp_OAMethod @sh
, 'GetString'
, @ret OUT
END
IF @err = 0
BEGIN
SELECT @msg = 'sp_OADestroy'
EXEC sp_OADestroy @sh
END
DECLARE @src varchar(8000)
, @desc varchar(8000)
IF @err = 0
SELECT [ret] = @ret
ELSE
BEGIN
EXEC sp_OAGetErrorInfo @sh, @src OUT, @desc OUT
PRINT @msg
PRINT @src
PRINT @desc
PRINT convert(varbinary(4), @err)
END
go
EXEC ecx
On Wednesday, January 31, 2007 2:27 AM
Razvan Socol wrote:
Here is an example of a call to a web service using SOAP Toolkitwithin SQL
Here is an example of a call to a web service using SOAP Toolkit
within SQL Server:
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'MSSOAP.SoapClient30', @object OUT
IF @hr <> 0 GOTO errorhandler
EXEC @hr = sp_OAMethod @object, 'MSSoapInit', NULL, 'http://
ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl'
IF @hr <> 0 GOTO errorhandler
DECLARE @Name varchar(1000)
EXEC @hr = sp_OAMethod @object, 'checkVat', NULL, 'RO', 19, NULL,
NULL, @Name OUT, NULL
IF @hr <> 0 GOTO errorhandler
PRINT @name
GOTO finish
errorhandler:
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
finish:
EXEC @hr = sp_OADestroy @object
The above code should print "BUCUR OBOR SA", which is the name of the
company having the VAT code "RO19" in Romania.
However, be advised that SOAP Toolkit is no longer supported (since
April 2005) and that using the sp_OA procedures is usually tricky.
Therefore you should consider upgrading to SQL Server 2005, where you
can create a CLR stored procedure and invoke the web service using the
standard .NET calls.
Razvan
On Thursday, February 01, 2007 7:22 PM
ekki wrote:
I tried to pull up this file but I get an error.
I tried to pull up this file but I get an error. "The page cannot be
displayed
There is a problem with the page you are trying to reach and it cannot be
displayed."
therefore I cannot see the method signature or the nature of the return
value. I also cannot run/veify that your code works.
from what I can see, what you are retrieving is a string, and you seem to be
doing it via an output parameter (since, (I think) the return value is what
you're declaring as null).
my methods don't return values in output parameters. what I need is a way
either to retrieve the XML document returned by the call, or specify (via
XPath or some other way) the nodes I need and retrieve the data directly.
can you help?
On Friday, February 02, 2007 1:09 AM
Razvan Socol wrote:
The VIES web service seems to have a problem (since yesterday).
The VIES web service seems to have a problem (since yesterday). Let's
hope they fix it soon.
I'm not very experienced in this kind of stuff, but I think that you
can specify the raw SOAP message and get the raw SOAP response by
using the SoapInvoke method.
If you don't want the raw SOAP response, but your web method is a
function that returns an XML, you should be able to get it by invoking
your method like this:
EXEC @hr = sp_OAMethod @object, 'MethodName', @Result OUT,
parameters...
Razvan
On Friday, February 02, 2007 12:47 PM
ekki wrote:
hmm...
hmm... I looked it up but that method seems to belong to the SoapServer30
object and I'm trying to be a client.
unfortunately, my methods don't returns strings with XML. they return
complex objects. I guess what I need to do is serialise the response so I
can parse it.
On Friday, February 02, 2007 12:58 PM
Razvan Socol wrote:
Re: Calling a web service in SQL2K
I am sorry for the confusion. You would probably get better answers in
the microsoft.public.xml.soap or microsoft.public.xml.soapsdk
newsgroups.
Razvan
On Friday, February 02, 2007 1:49 PM
ekki wrote:
cool. thanks for the references.
cool. thanks for the references.
Submitted via EggHeadCafe - Software Developer Portal of Choice
IE 6.0 Delivers Enhancements and Challenges
http://www.eggheadcafe.com/tutorials/aspnet/5cdd6374-4f49-483a-b143-c0...a164bcc >> Stay informed about: Calling a web service in SQL2K