4

I want to call a webservice from TSQL in SQL Server 2000. I tried with the following code:

Declare @Object as Int; 
Declare @ResponseText as Varchar(8000);
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get','http://server/ws/service1.asmx/Test', 'false';
Exec sp_OAMethod @Object, 'send';
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT;
Select @ResponseText Resultado;
Exec sp_OADestroy @Object;

For this to work I had to enable Ole Automation:

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO

In my test server works fine, the problem is that on the production server to run

sp_configure 'Ole Automation Procedures', 1; 

I get the following error:

The configuration option 'Ole Automation Procedures' does not exist, or it may be an advanced option.

When running

exec sp_configure 

on the test server brings the record "Ole Automation Procedures" on the production server not.

Update

I modify the code to catch the error:

Declare @Object as Int; 
Declare @ResponseText as Varchar(8000);
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get','http://server/ws/service1.asmx/Test', 'false';
Exec sp_OAMethod @Object, 'send';
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT;
EXEC sp_OAGetErrorInfo @Object
Select @ResponseText Resultado;
Exec sp_OADestroy @Object;

The instruction "sp_OAGetErrorInfo EXEC @ Object" return: (0x8004271A ) Error in srv_convert.

According to Microsoft (link) is a problem of SqlServer. Since in my case the result of the webservice exceed 4000 characters.

How I can call a webservice from TSQL?

6
  • 1
    Did you run sp_configure 'show advanced options', 1; on production as well? Commented Jan 10, 2013 at 14:07
  • Check the SQL Server versions on both your test and production servers. It sounds like they are different. Commented Jan 10, 2013 at 14:14
  • @Andomar, sp_configure 'show advanced options', 1; in the production server worked well. Commented Jan 10, 2013 at 14:14
  • What's the result of this query: SELECT * FROM master.dbo.sysobjects WHERE name LIKE '%sp_OA%' AND xtype = 'X' Commented Jan 10, 2013 at 14:29
  • @Andomar, the result is: sp_OACreate, sp_OADestroy, sp_OAGetErrorInfo, sp_OAGetProperty, sp_OAMethod, sp_OASetProperty, sp_OAStop Commented Jan 10, 2013 at 14:57

3 Answers 3

2

I just stumbled upon same error - "(0x8004271A ) Error in srv_convert."

To overcome char limitations, use #tmp table like below:

Create table #tmp(dt nvarchar(max))
insert into #tmp 
exec @hr =sp_OAGetProperty @objWinHttp, 'ResponseText'
Select dt from #tmp -- single column/single row.
Drop Table #tmp -- clean up

Solution Source

Sign up to request clarification or add additional context in comments.

Comments

1

heey i have maybe some help for you if you want to call to call a HTTP web service from T-SQL (no SQLCLR) You can automate the XMLHTTP server object using the Object Automation extended stored procedures.

Example

I suggest you use the CLR or an SSIS package though.

1 Comment

Thanks but in this case would also have to enable Ole Automation Procedure which is where I have the problem.
1

I solved it the following way:
Create a VBScript file (callWS.vbs) with the following code:

if WScript.Arguments.Count = 1 then
    Set http = CreateObject("Microsoft.XmlHttp")
    http.open "GET", WScript.Arguments(0), FALSE
    http.send ""
    WScript.Echo http.responseText
else
    WScript.Echo "Not was provided the WS address."
end if

Then in TSQL:

declare @Command varchar(100)
declare @RetInfo varchar(8000)
select @Command = 'cscript c:\callWS.vbs "http://server/ws/service1.asmx/Test"'
print @Command
exec @RetInfo = master.dbo.xp_cmdshell @Command
print @RetInfo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.