SQL Tips by Namwar Rizvi

May 12, 2007

Using Stored Procedure as a Web Service in SQL Server 2005

Filed under: New Features, SQL Server 2005, Web Services, tips — namwar @ 5:43 pm

Web Services are getting more and more popular these days. SQL Server 2005 provides an excellent set of features to expose stored procedures as web services. Following is a quick and easy way to implement a stored procedure as a web service. It is just an example but gives you a clear idea how to use SQL Server 2005 for web service implementation:

Set ANSI_NULLS ON
Set QUOTED_IDENTIFIER ON
go

—Sample STored procedure to retrieve Server Date and Time
Create Proc usp_GetServerTime
as
Select GetDate()

—Creating Web Service
CREATE ENDPOINT [EP_GetServerTime]
STATE=STARTED
AS HTTP
(
PATH=‘/URL_GetServerTime’,
PORTS = (CLEAR),
AUTHENTICATION = (INTEGRATED),
SITE=‘DBSERVER’
)
FOR SOAP
(
WEBMETHOD ‘GetServerTime’
(
NAME=‘TestDB.dbo.usp_GetServerTime’
),
WSDL=DEFAULT,
DATABASE=‘TestDB’,
NAMESPACE=DEFAULT
)

For details on web service support in SQL Server 2005, please visit

http://www.developer.com/db/article.php/3390241

Blog at WordPress.com.