How to establish an HTTP endpoint in SQL Server 2005

Source: Internet
Author: User
Tags soap sql new features return xmlns wsdl

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 ');



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.