Using SQL Server 2000 to provide existing code as a Web service

Source: Internet
Author: User
Tags http request soap microsoft sql server xmlns xsl xsl file

First, Introduction

Microsoft SQL Server 2000 's XML functionality simplifies the task of providing existing code as a Web service. This article focuses on the transformation between incoming and outgoing Transact SQL code data and XML messages (used between Web service clients and servers).

Ii. existing code in SQL Server 2000

SQL Server 2000 's XML capabilities simplify the process of providing existing Transact SQL code as a Web service. This relies on two XML features in SQL Server 2000:

1. Extensions to Transact SQL can transform relational data into XML and parse the incoming XML. The ISAPI template feature allows incoming HTTP requests to be applied to Transact SQL code, and you can use XSL style sheets to convert outgoing XML. SQL Server can return XML to an XML template as long as you can use the FOR XML clause to "select" Data.

2.SQL Server XML Template

SQL Server XML templates perform the following tasks transparently:

Decoding incoming HTTP requests apply parameters to Transact SQL query execution query use XSL Transform outgoing XML read data The following example executes the Transact SQL specified in the ISAPI template. If necessary, the HTTP request can be passed to the Transact SQL code and parsed by the code. Depending on the. xsl file specified in the template, the returned XML is converted to soap and returned to the customer of the Web service:

Exec GetOrdersXML
以下是模板中引用的 XSL样式表,它将存储过程中的 XML转换为 SOAP:
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="Some-URI">

Finally, the following stored procedure code uses the FOR XML EXPLICIT clause in the Transact SQL SELECT statement to return the XML. Order and order details are selected from a separate table and then merged into the XML hierarchy:

/* Order is parent XML element * *

Select 1 as Tag, NULL as Parent,
Orders.OrderId AS [Order!1!OrderId],
Orders.OrderStatus AS [Order!1!OrderStatus],
Orders.OrderDate AS [Order!1!OrderDate],
Orders.SubTotal AS [Order!1!SubTotal],
Orders.Tax AS [Order!1!Tax],
Orders.ShippingHandling AS [Order!1!ShippingHandling],
Orders.ShipToName AS [Order!1!ShipToName],
Orders.ShipToAddressId AS [Order!1!ShipToAddressId],
NULL AS [OrderDetail!2!OrderDetailId],
NULL AS [OrderDetail!2!OrderId],
NULL AS [OrderDetail!2!ItemId],
NULL AS [OrderDetail!2!UnitPrice],
NULL AS [OrderDetail!2!Quantity]
from Orders
UNION ALL

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.