Browse DevX
Sign up for e-mail newsletters from DevX


Easy Web Services with SQL Server 2005 HTTP Endpoints : Page 2

By leveraging HTTP endpoints and SOAP in SQL Server 2005, developers can bypass IIS and use SQL Server directly to expose Web services and simplify their applications.

Creating and Launching Endpoints
You use the CREATE ENDPOINT statement to create an endpoint as shown below:

       PATH = '/AWpersons',
       PORTS = (CLEAR),
       SITE = 'sqlidw14'
       WEBMETHOD 'PersonInfo'
       WSDL = DEFAULT,
       DATABASE = 'AdventureWorks',
       NAMESPACE = 'http://Adventure-Works/Persons'
The CREATE ENDPOINT statement has several key components. The STATE argument is set to STARTED, which indicates that the endpoint listener is running. Other options included STOPPED and DISABLED for handling service endpoints. The rest of the code sits in the AS HTTP clause or the FOR SOAP clause. AS HTTP sets HTTP as the transport for the endpoint and includes the following settings:

  • PATH—Specifies the URL for the service endpoint, and in this example defaults to the server name and the path specified, e.g. http://yourdemoserver/AWpersons.
  • AUTHENTICATION—Specifies the type of authentication to be used for the service endpoint. A variety of authentication mechanisms are supported, including BASIC, INTEGRATED (uses Windows security), NTLM, and KERBEROS.
  • PORTS—Specifies what port type to use. CLEAR or SSL are the supported options, with CLEAR accepting only HTTP requests and SSL requiring HTTPS.
  • SITE—Specifies the name of the host computer for the endpoint.
The FOR SOAP clause supports the following arguments:

  • WEBMETHOD—Specifies the Web method used to send requests via the HTTP SOAP endpoint. You can declare multiple Web methods per endpoint.
  • BATCHES—Specifies whether not the endpoint supports ad-hoc SQL requests. This is disabled by default.
  • WSDL—Specifies whether the endpoint supports WSDL. For custom WSDL implementations, you can provide a stored procedure name that returns a custom WSDL implementation.
  • DATABASE—Specifies the name of the database where the requested operation is executed in context.
  • NAMESPACE—Specifies a namespace for the endpoint.
After creating the endpoint, you can submit an HTTP request to the server to ensure that the endpoint is responding. A simple test is to navigate to http://sqlidw14/awpersons?wsdl (substitute your own server and endpoint name), which, if the endpoint is responding, will return the WSDL for your exposed service.

To consume the Web service, simply follow the steps for adding a Web reference and invoking a Web service in a standard .NET application. The downloadable sample application includes a simple application for testing purposes, including the following code to invoke the Web service:

   sqlidw14.SQLEP_AWPersons proxy = new 
   i = Convert.ToInt32(txtID.Text);
   proxy.UseDefaultCredentials = true;   
   results = proxy.PersonInfo(i);
After the Web service returns the results, the sample client application displays the data.

Thanks for your registration, follow us on our social networks to keep up-to-date