What is an HTTP Endpoint in Sql Server? Well, it is a way to
create a usable interface using HTTP or TCP for SOAP, T-Sql, Service
Brokering and a few other things. I’m just going to tell you,
quick and simple, about creating a web service to return data, although
you can return scalar values, messages and errors too. The
results returned are serialized into Xml. If you have Windows
2003, you don’t have to have IIS installed. Sql server will use
the http.sys module in the Win2K3 kernel.
So lets look at creating a usable web service from within Sql Server. Lets start with creating a stored procedure.
Create stored procedure to return list of employees
use adventureworks
go
create procedure dbo.GetEmployees
As
select e.employeeid, e.title, c.FirstName + ‘ ‘ + c.Lastname As Fullname from HumanResources.employee e
inner join person.contact c
on e.contactid = c.contactid
go
Now, lets create our sql server web service, known as an HTTP ENDPOINT.
The Sql 2005 code to create the HTTP ENDPOINT
use adventureworks
go
CREATE ENDPOINT GetEmployees
STATE = STARTED
AS HTTP
(
PATH = ‘/Employee’,
AUTHENTICATION = (INTEGRATED),
PORTS = (CLEAR),
SITE = ‘localhost’
)
FOR SOAP
(
WEBMETHOD ‘EmployeeList’
(NAME=’AdventureWorks.dbo.GetEmployees’),
BATCHES = DISABLED,
WSDL = DEFAULT,
DATABASE = ‘AdventureWorks’,
NAMESPACE = ‘http://AdventureWorks/Employee’
)
go
There we go. We now have a web service! You
access and use this endpoint the same way you would any other web
service. You can create multiple WEBMETHODs in a single endpoint,
just seperate them with commas in the FOR SOAP statement.
Here are the values you can use for the “STATE” argument:
Here are the “AS HTTP” arguments you can use:
So, now lets put our endpoint to work. First, create a new
windows application project, and add a web reference to it. When
you browse for the web service, it won’t be discovered
automatically. You have to type in the url and click “go”.
The url in this case is http://localhost/Employee?wsdl.
You’ll see the EmployeeList method come up in the list, just like using
any other web service. Go ahead and add the service and rename it
to whatever. I called mine “adventureWorksService”.