|
Enabling SQL Server For Web Services
|
|
In my earlier article on configuring
web queries in SQL Server, we saw the various steps that need to be configured in the IIS
configuration tool for SQL Server. As a continuation to that, in this article we will see how to enable
SQL Server to accept SOAP requests. For more information on accessing the IIS configuration tool, see
the other article pointed to earlier.
The specific steps to configure the IIS configuration tool for SOAP requests
are:
-
In the configure IIS support tool, choose the virtual directory (pubs
in our example) and right-click to select the properties option.
-
In the properties dialog box, select the Virtual Names tab and create
a new virtual name of soap type. The following figure shows all the options that need to be
set.

-
After configuring the virtual names, select the created name and choose Configure.
-
In the resulting dialog box, click on the <New method mapping> option and
configure the options to point to the appropriate SQL Server object. In the example below, I've pointed the
configuration to a function called GetAuthorsCount. The following figure shows the
configuration.

The function that was referenced in the above example is as follows:
IF (OBJECT_ID ('dbo.GetAuthorsCount') IS NOT NULL)
DROP FUNCTION dbo.GetAuthorsCount
GO
CREATE FUNCTION dbo.GetAuthorsCount () RETURNS INT AS
BEGIN
DECLARE @recordCount INT
SET @recordCount = 0
SELECT @recordCount = COUNT(*) FROM authors
RETURN (@recordCount)
END
http://machineName/virtualFolder/soapVirtualName?WSDL
For example, given the configurations made above, the actual URL will be:
http://lp-srinivas/pubs/soap?wsdl
Once you hit on the URL, the generated WSDL file will be shown. The following
figure shows a portion of the WSDL file.

Now that you have all the necessary files generated, you can open up Visual
Studio .NET and add a web reference to above URL and get access to all the objects that you had
exposed. Have fun!! For another article that talks about similar concepts, refer to Vinod's article
here.
|