dat304 leveraging xml and http with sql server irwin dolobowsky program manager webdata group
TRANSCRIPT
Agenda
SQLXML Overview
Data Access Methods
FOR XML Queries over HTTP
XPath Queries over HTTP
Binary Data
Xml Templates & Updategrams
Web Servies
Demos
Configuring SQL Server to work over HTTP (virtual directories)
Executing Sql queries over HTTP
Executing XPath queries over HTTP
Xml Templates & Updategrams
SQLXML Web Services
The Two Worlds
SQLSQLServerServer
RowSetRowSet
SQLSQL
Relational Relational worldworld
LanguageLanguage
Data Data storagestorage
Data Data outputoutput
XML XML worldworld
XMLXMLFilesFiles
XPathXPathXQueryXQuery
XML/XML/HTMLHTML
XMLXMLViewView
SQLXML SQLXML – –
Bringing Bringing worlds worlds
togethertogether
Query/Update Technologies
FOR XML (raw, auto, nested, explicit)SQL language extension to retrieve XML instead of rowsets
XML Views – XPathWork with your relational database as if it was XML file (through annotated schema)
Updategrams/DiffgramsUpdate through XML View
BulkloadShred large XML files into existing tables
Data Access Methods
HTTP Access via URLSQL Query
XPath Query
XML Templates
DBObjects
Web services with SQL Virtual Directories
ADO / OLEDB
.NET access through SQLXML Managed Classes or ADO.NET
Custom Web Services
HTTP access to SqlXml
Easy as setting up a virtual directory
Can query directly with query strings
Best practices:Use templates for abstraction
No blank sa passwords!
Create the physical directory first
Steps: Configure XML support in IIS for
SQL Server Launch Click the Start button and select Programs Microsoft SQL Server Configure SQL XML Support In IIS
Create a new virtual directory
Set physical path
Configure connection security
Choose data source
Steps: Configure XML support in IIS for
SQL Server Configure access settings
Allow URL Queries
Allow Template Queries (*Default)
Allow XPath
Other tabs…Virtual Names (you will see this later)
Advanced
Configuring XML support in IIS for Sql Server
Irwin Dolobowsky
Program Manager
Webdata Group
demodemo
Construct a simple HTTP Query
SELECT * from Customers FOR XML AUTO
Convert it to an HTTP request, by concatenating it with plus-sign (+) delimiters into:
SELECT+*+FROM+CUSTOMERS+FOR+XML+AUTO
Append that onto the URL for the virtual directory that you’ve created, by using the sql querystring parameter
http://localhost/NorthwindCustomers?sql= SELECT+*+FROM+CUSTOMERS+FOR+XML+AUTO
XPath queries over HTTPUse XPath to query SQL Database as if it was an XML fileQuery over Xml View
Mapping XSD to Relational SchemaMuch easier that FOR XML EXPLICITAbstract away Database
StepsCreate annotated XSD (mapping/Xml View)Configure the virtual Schema directoryQuery against AXSD with XPath over HTTP
Execute XPath Queries Execute XPath Queries over HTTPover HTTP
Irwin Dolobowsky
Program Manager
Webdata Group
demodemo
Using DbObjectsEnables you to return BLOBsEach query translates into a SQL statementQuery returning a character column
http://localhost/demos/dbobject/Employees[@EmployeeID=1]/@LastName
Query returning a blob columnhttp://
localhost/demos/dbobject/Employees[@EmployeeID=1]/@Photo
Query using parametershttp://localhost/demos/dbobject/
Employees[@EmployeeID=$eid]/@Photo?eid=1
Working with BLOBs
TechniquesBase64
DBObject
How to decide?Do you have access to the pointer (location) from DBObject?
DBObject faster
Xml Templates
XmlDocument with embedded queriesFOR XML QueriesXPath over Annotated XSD
When template is executed, query results are filled in
Dynamic XML documentParameterizedUse templates over raw URL queries
Get cachingEncapsulationSecurityControl
Steps: XML Templates over HTTP
Enable virtual directory settings Create query in template format
<sql:query></sql:query>Create the physical template directoryConfigure the virtual template mappingSave into XML file in template directoryJust point to the template with a URL
Using sql:query
<NWCustomers xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query> SELECT CustomerID,
CompanyName, City, Country
FROM Customers FOR XML AUTO, ELEMENTS </sql:query></NWCustomers>
Updategrams & XML ViewsModify the database through the XML ViewDeclare before and after images of the XML (what it is now, and what you want it to be)Optimistic concurrency control ensures that the transaction takes place only if the before image matches the current database stateEach updategram is translated into one or more INSERT, UPDATE, and DELETE statements, carried out as a single transaction
Updategrams And XMLViews<updategram-example> <updg:sync mapping-schema=“schema.xsd”
xmlns:updg=“urn:schemas-microsoft-com:xml-updategram”>
<updg:before> <Customer CustomerID=“LAZYK” Address=“12 Orchestra
Terrace”> <Order OrderID=“27” UnitPrice=“100” Quantity=“1000” /> </Customer></updg:before>
<updg:after> <Customer CustomerID=“LAZYK” Address=“8 Opera Court”/></updg:after>
</updg:sync></updategram-example>
XML Templates & Updategrams: Tying it all togetherIrwin Dolobowsky
Program Manager
Webdata Group
demodemo
Web Services Overview
Web Services expose Stored Procedures and XML Templates
Messaging done according to SOAP 1.1 standard
Variety of response options
Can run on database server or mid-tierWherever IIS is
Simple UI for configurationEven DBA’s can do it!
What Does SQLXML Do For You?
Creates Web Services Description Language (WSDL) file
Describes Web Service
Indicates what Methods are available
Difficult to write by hand. WE DO IT FOR YOU!
Parse SOAP requests
Return proper SOAP response
Creating A Web Service
Use the configuration tool to create a Virtual Directory (VDir)
Create a Virtual Name of type “SOAP”Name your Web Service
Give it a domain
You Have a Web Service!You Have a Web Service!
Now to add some methods…Now to add some methods…
XML Template Methods
Browse for an XML Template
Choose Web Method name
Results always returned in “XML Objects” mode
Stored Procedure Methods
Select Stored Procedure from listGenerated from login used for the VDir
Choose Web Method name
Select Output Formatting RAW or NESTED
Select Response Type XML Objects
Dataset Objects
Single Dataset
Visual Studio.NET Integration
SQLXML 3.0 Web Services designed for Visual Studio.NET
In a Visual Studio.NET Project, “Add Web Reference” to your Web Service
Proxy classes generated for your methods
Forget that you are not accessing local information
Visual Studio.NET takes care of the SOAP messaging and XML serialization / de-serialization for you
Exposing and AccessingExposing and AccessingSProcs as Web ServicesSProcs as Web Services
Irwin Dolobowsky
Program Manager
Webdata Group
demodemo
Response Types
All Responses are XML / SOAPResponse Type dictates what Visual Studio.NET De-Serializes the XML into
Other clients will just see XML
Single Dataset Response Limitations
No Error InformationEither a dataset comes back or it doesn’t, no other messages
Single Result Sets OnlyUse Dataset Objects mode instead
Community Resources
Main web page and download SQLXML releases at:
http://msdn.microsoft.com/sqlxml/
Contactsnews:microsoft.public.sqlserver.xmlEmail me: [email protected]
DocumentationSQL Server 2000 Documentation (Books Online)Web Release documentationBooks
Community Resources
Community Resourceshttp://www.microsoft.com/communities/default.mspx
Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/
NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx
User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx
© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.