Avatar of lankapala
lankapala

asked on 

T-sql Web servcies

Hi,
I need to run .wdsl web service from T-sql (write stored procedure).Any idea

See link below
http://ws.afd.co.uk/PCE_WebService.asmx?WSDL
.NET Programming* T-SQLMicrosoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
Pawan Kumar
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

You should be able to do it similarly to this:
CREATE PROCEDURE GetAirportInfo
@AirportCode varchar(20)
AS
BEGIN
    Declare @Object as Int;
    Declare @ResponseText as Varchar(8000);

    Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
    Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://www.webservicex.net/airport.asmx/getAirportInformationByAirportCode?airportCode=' + @AirportCode,'false'
    Exec sp_OAMethod @Object, 'send'
    Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
    Select @ResponseText
    Exec sp_OADestroy @Object
END

Open in new window

Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Which SQL Server are you using SQL 2008  ?

For that i think you need to use SQL SERVER CLR or SSIS package.
For clr refer - https://blogs.msdn.microsoft.com/spike/2010/11/25/how-to-consume-a-web-service-from-within-sql-server-using-sql-clr/
For SSIS package - it is same as you call it in .NET code. here you need to use the script task.

Otherwise you can check the below code. TO consume a webservice you need 3 sps called sp_OACreate, sp_OAMethod and sp_OADestroy. I have created a stored procedure for you. If you want to pass the webservice name dynamically you can change it to parameters.

CREATE PROC CallWebService
AS
BEGIN

	Declare @Ob as Int, @ReturnData as Varchar(MAX);
	Exec sp_OACreate 'MSXML2.XMLHTTP', @Ob OUT;
	Exec sp_OAMethod @Ob, 'open', NULL, 'get', 'http://ws.afd.co.uk/PCE_WebService.asmx?WSDL','false'
	Exec sp_OAMethod @Ob, 'send'
	Exec sp_OAMethod @Ob, 'responseText', @ReturnData OUTPUT
	Select @ReturnData
	Exec sp_OADestroy @Ob

END

Open in new window

If you want to learn the entire code then you can follow from codeproject
https://www.codeproject.com/Articles/428200/How-to-invoke-a-Web-Service-from-a-Stored-Procedur
Avatar of lankapala
lankapala

ASKER

Hi, I tried above codes many times.Never worked.That's the reason i asking how to do that.
if you go to
http://ws.afd.co.uk/PCE_WebService.asmx?WSDL

i'm looking how to pass parameters.

PCEWebService.PostcodeEverywhere.AddressList(String strSerialNumber, String strPassword, String strUserID, String strPostcode, String strProperty, String strCountyType)
SOLUTION
Avatar of EugeneZ
EugeneZ
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

>> I tried above codes many times.Never worked.That's the reason i asking how to do that.

asking again - Which version of SQL Server are you using?
Avatar of lankapala
lankapala

ASKER

@Kyle Abrahams
I used same exactly like you used,But still not working see my code

http://ws.afd.co.uk/PCE_WebService.asmx/AddressList?strSerialNumber=1111&strPassword=444&strUserID=Test1&strPostcode=NE3%202NS&strProperty=&strCountyType=Tyne

This is working in the IE explore,But not the SQL server

and also i'm getting error message From  your code  +   (+ @AirportCode) Incorrect syntax near +

 Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://www.webservicex.net/airport.asmx/getAirportInformationByAirportCode?airportCode=' + @AirportCode,'false'
Avatar of lankapala
lankapala

ASKER

@Pawan Kumar
Sql Server 2008R2
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

can you pls share your entire code. Will fix.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of lankapala
lankapala

ASKER

@Pawan Kumar:
Still NULL retun
But sameway it's working at IE browser
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Al@author

Do u know any parameter values where for which it will return value?
Avatar of ukerandi
ukerandi
Flag of United Kingdom of Great Britain and Northern Ireland image

Select @ReturnData?
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

I think is once you pass proper values of parameters then you will get proper response if it is there. My code is working fine.

EXEC CallWebService '1111','444','Test1','NE3 2NS','','Tyne'

Open in new window

SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Question abandoned
Provided multiple solutions.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo