SQL2005 provides a new way to execute stored procedures or T-SQL, which can be published to the server as a Web service without the need to use the new features of IIS to expose HTTP endpoints to users via HTTP APIs, supported on WinXP SP2 and WIN2003
Setting up an HTTP endpoint is very simple, as follows:
CREATE ENDPOINT MyEndpoint?
STATE = STARTED
AS HTTP (
AUTHENTICATION = (INTEGRATED),
PATH = '/sql/myendpoint',
PORTS = (CLEAR) )
FOR SOAP (
BATCHES = ENABLED,
WSDL = DEFAULT
)
In the case above I created an endpoint named Myendpoint, which listens to T-SQL statements in Http://localhost/sql/myendpoint, and you can test it using the following URL
Http://localhost/sql/myendpoint?wsdl.
The above URL can also be attached to a rich parameter, specifically see SQL Help
The following example shows how to call an endpoint to execute a T-SQL statement through Javscript, as follows:
function Sendbatchrequest (strServerName, Strurlpath, strquery)
{
var objxmlhttp = null;
var strrequest = "";
objXmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
Objxmlhttp.open ("POST", "http://" + strServerName + Strurlpath, false);
Objxmlhttp.setrequestheader ("Content-type", "Text/xml");
Objxmlhttp.setrequestheader ("Host", strservername);
Strrequest = "<soap-env:envelope
xmlns:soap-env= ' http://schemas.xmlsoap.org/soap/envelope/'
Xmlns:sql= ' Http://schemas.microsoft.com/sqlserver/2004/SOAP ' >
<SOAP-ENV:Body>
<sql:sqlbatch>
<sql:BatchCommands> "+ strquery +" </sql:BatchCommands>
</sql:sqlbatch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> ";
Objxmlhttp.send (strrequest);
if (Objxmlhttp.status = 200)
return objXmlHttp.responseXML.xml;
Else
Return "";
}
var response = sendbatchrequest (' localhost ', '/sql/myendpoint ', ' Select * from sys.http_endpoints ');