SQL Server 2005 透過 **HTTP.SYS** 核心驅動程式,直接在資料庫引擎層監聽 HTTP 請求,將 T-SQL 批次或預存程序以 **SOAP Web Service** 形式發布。支援 Windows XP SP2 / Server 2003+。
CREATE ENDPOINT MyEndpoint
STATE = STARTED
AS HTTP (
AUTHENTICATION = (INTEGRATED), -- Windows 整合驗證
PATH = '/sql/myendpoint', -- URL 路徑
PORTS = (CLEAR) -- HTTP 明文埠 (80)
)
FOR SOAP (
BATCHES = ENABLED, -- 允許任意 T-SQL 批次
WSDL = DEFAULT -- 自動產生 WSDL
);
https://localhost/sql/myendpoint?wsdlfunction SendBatchRequest(strServerName, strUrlPath, strQuery) {
var objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
objXMLHttp.open("POST", "https://" + strServerName + strUrlPath, false);
objXMLHttp.setRequestHeader("Content-Type", "text/xml");
objXMLHttp.setRequestHeader("Host", strServerName);
var strRequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV='https://schemas.xmlsoap.org/soap/envelope/' xmlns:sql='https://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;
return "";
}
var result = SendBatchRequest('localhost', '/sql/myendpoint', 'SELECT * FROM sys.http_endpoints');
PORTS = (SSL))、限制 BATCHES 僅允許特定預存程序 (WEBMETHODS),避免任意 SQL 注入風險。