這個新特點通過http api把http端點暴露給用戶,在winxp sp2和win2003上被支持建立一個http端點是非常簡單的,如下
create endpoint myendpoint?
state = started
as http (
authentication = (integrated),
path = '/sql/myendpoint',
ports = (clear) )
for soap (
batches = enabled,
wsdl = default
)
在上面的案例中我建立一個命名為myendpoint的端點,它在http://localhost/sql/myendpoint監聽t-sql語句,你可以使用下面url測試它
http://localhost/sql/myendpoint?wsdl.
上面這個url還可以附加很豐富的參數,具體參見sql幫助
下面這個例子顯示如何通過javscript來調用端點執行t-sql語句,如下
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' );
新聞熱點
疑難解答