Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Calling a web service in SQL2K

 
   Database Help (Home) -> Programming RSS
Next:  SQL Proc runs on one server and not on another  
Author Message
ekkis

External


Since: Mar 13, 2007
Posts: 2



(Msg. 1) Posted: Tue Jan 30, 2007 6:56 pm
Post subject: Calling a web service in SQL2K
Archived from groups: microsoft>public>sqlserver>programming (more info?)

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

 >> Stay informed about: Calling a web service in SQL2K 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 2) Posted: Tue Jan 30, 2007 11:27 pm
Post subject: Re: Calling a web service in SQL2K [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

 >> Stay informed about: Calling a web service in SQL2K 
Back to top
Login to vote
ekkis

External


Since: Mar 13, 2007
Posts: 2



(Msg. 3) Posted: Thu Feb 01, 2007 4:22 pm
Post subject: Re: Calling a web service in SQL2K [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl

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.

> DECLARE @Name varchar(1000)
>
> EXEC @hr = sp_OAMethod @object, 'checkVat', NULL, 'RO', 19, NULL,
> NULL, @Name OUT, NULL

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?
 >> Stay informed about: Calling a web service in SQL2K 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 4) Posted: Thu Feb 01, 2007 10:09 pm
Post subject: Re: Calling a web service in SQL2K [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The VIES web service seems to have a problem (since yesterday). Let's
hope they fix it soon.

> 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.

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
 >> Stay informed about: Calling a web service in SQL2K 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 5) Posted: Fri Feb 02, 2007 9:58 am
Post subject: Re: Calling a web service in SQL2K [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 2, 7:47 pm, ekkis wrote:
> hmm... I looked it up but that method seems to belong to the SoapServer30
> object and I'm trying to be a client.

I'm sorry for the confusion. You would probably get better answers in
the microsoft.public.xml.soap or microsoft.public.xml.soapsdk
newsgroups.

Razvan
 >> Stay informed about: Calling a web service in SQL2K 
Back to top
Login to vote
rakesh gavande

External


Since: Jan 13, 2010
Posts: 1



(Msg. 6) Posted: Wed Jan 13, 2010 5:01 am
Post subject: Can anybody solve my problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL2K XML - This is SQL 2005 syntax: DECLARE @xml XML SELECT @xml = CAST( y AS NVARCHAR(MAX) ) FROM OPENROWSET ( BULK N'C:\temp\myxml.xml', SINGLE_CLOB ) AS x (y) SELECT x.y.value('(mynode1/text())[1]', 'INT') AS node1, x.y.value('(mynode2/text())[1]',..

SQL2K Error Log - Is it possible to set (or limit) the size of the error log file for SQL Server 2000? I have looked all over the Ent Mgr and been Googling for a while now, but in neither case finding anything. I have only seen where I can set the location (Server..

List locked tables in SQL2K - Hello everyone, i am trying to track lock problems on a db in SQL Server 2K. I know that using DBCC OPENTRAN and then passing the spid to DBCC INPUTBUFFER i can list the queries that are used in transactions. What I dont know is: 1. List all locked....

how query Active Directory from sql2k server? - I've seen this linked server syntax many times in the group. but it didn't work for me, maybe someone can explain it better for me? sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource' i know that: * &qu...

Function to find the max of two dates (SQL2K) - Hi I need a query to report compliance with a 30 working day KPI of depatched items. That is how long after receipt of a key piece of info the despatch is made. To make matters even more complex, to make a despatch we actually need two pieces of info, an...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]