Title: SAS 917: Web Services with Adaptive Server Anywhere
1SAS 917 Web Services with Adaptive Server
Anywhere
John Poole Software Developer, iAnywhere
Solutions jpoole_at_ianywhere.com August 6, 2003
2Agenda
- Introduction to Web Services
- Thirty Second Web Service
- WeatherData Web Service
- Server Switch
- Web Service Statements
- Web Service Types
- Server Addressing
- Service Determination
- Parameter Handling
- Functions and System Functions
3Introduction to Web Services
- What is a web service?
- A web service is a programmatic interface that is
used for application-to-application communication
over a network. Web services use widely-used
technologies and standards such as XML and HTTP
in order to make these interfaces platform and
language independent. - How does Banff support web services?
- Banff includes an embedded HTTP server, which
allows developers to create and deploy web
services directly from the database. - Web services in Banff support a number of
different technologies and standards, including
HTTP, XML, SOAP, and WSDL.
4Thirty Second Web Service
- From the command line
- dbinit web.db
- dbeng9 -xs http web.db
- From dbisql
- create service tables type xml authorization
off user dba as select from systable - From a web browser
- Access http//localhost/web/tables
5Thirty Second Web Service
6Thirty Second Web Service
- lt?xml version"1.0" ?gt ltrootgt ltrow
table_id"1" file_id"0" count"182"
first_page"1" last_page"620" primary_root"8"
creator"0" first_ext_page"213"
last_ext_page"316" table_page_count"19"
ext_page_count"12" table_name"SYSTABLE"
table_type"BASE" replicate"N" server_type"SA"
primary_hash_limit"10" page_map_start"0" /gt
ltrow table_id"2" file_id"0" count"1325"
first_page"2" last_page"656" primary_root"9"
creator"0" first_ext_page"0" last_ext_page"0"
table_page_count"35" ext_page_count"0"
table_name"SYSCOLUMN" table_type"BASE"
replicate"N" server_type"SA" primary_hash_limit
"10" page_map_start"0" /gt - ...
- lt/rootgt
7Thirty Second Web Service
C Example static void Main(string args)
XmlTextReader reader new XmlTextReader(
"http//localhost/tables" ) while(
reader.Read() ) switch( reader.NodeType )
case XmlNodeType.Element if( reader.Name
"row" ) Console.WriteLine(
reader.GetAttribute( "table_id" )
) Console.WriteLine( reader.GetAttribute(
"table_name" ) ) break
8Thirty Second Web Service
Python Example import xml.sax class DocHandler(
xml.sax.ContentHandler ) def startElement(
self, name, attrs ) if name
'row' table_id attrs.getValue( 'table_id'
) table_name attrs.getValue( 'table_name'
) print 's s' ( table_id, table_name
) parser xml.sax.make_parser() parser.setCon
tentHandler( DocHandler() ) parser.parse(
'http//localhost/tables' )
9WeatherData
- create table weatherData( year int, day int,
clock int, humidity float(1), temperature
float(2), pressure float(1), direction float(1),
speed float(3) ) - create procedure getWeatherData( in y int, in d
int )begin select clock, temperature,
humidity, pressure, direction, speed from
weatherData where year y and day d order by
clockend - create service techwave type 'dish' authorization
off user dba using "techwave"create service
"techwave/getWeatherDataXml" type 'xml'
authorization off user dba as call
getWeatherData( year, day )create service
"techwave/getWeatherDataSoap" type 'soap'
authorization off user dba as call
getWeatherData( year, day )
10WeatherData
11WeatherData
12WeatherData
- private void button1_Click(object sender,
System.EventArgs e) - localhost.techwave service new
localhost.techwave() DataSet ds null int
sqlcode - try ds service.getWeatherDataSoap(
textBox1.Text, textBox2.Text, - out sqlcode
) - if( sqlcode ! 0 ) MessageBox.Show(
"Database error, SQLCODE " sqlcode )
else dataGrid1.DataSource ds
dataGrid1.DataMember ds.Tables0.TableName
catch( Exception ex )
MessageBox.Show( ex.Message )
13WeatherData
14Server Switch
- New server switch -xs
- Controls how the server handles web services
- Valid options
- http listen for http connections
- https listen for https connections
- all listen for both http and https connections
- none don't listen for any connections (default)
- Options
- http and https can take options enclosed in () or
- ServerPort
- MyIP
- DatabaseName
- Timeout
15Web Service Statements
- Four new statements
- CREATE SERVICE identifier attributes AS
statement - ALTER SERVICE identifier attributes AS
statement NULL - DROP SERVICE identifier
- COMMENT ON SERVICE identifier IS comment
- Attributes
- TYPE string
- AUTHORIZATION ON OFF
- SECURE ON OFF
- USER user NULL
- URL PATH ON OFF ELEMENTS
- USING identifier
16Web Service Types
- XML
- query service the result set is returned as XML
- HTML
- query service the result set is returned as HTML
- RAW
- query service the result set is returned as-is
- SOAP
- query service the request is sent as a SOAP
request and the result set is returned as a SOAP
response - DISH
- proxy service DISH services act as a proxies for
SOAP services - DISH services also generate WSDL for SOAP services
17Server Addressing
- ltschemegt//lthostgtltportgt/ltdbngt/ltservicegt?ltpar
amsgt - scheme http or https
- host hostname or ip address of the server
- port port number the server is listening on
- dbn database that contains the service
- service name of the service
- params list of service parameters
- http//localhost80/web/tables
- http//localhost/tables
- both URLs point to the same service
18Service Determination
- Determine which database will handle the request
- DatabaseName influences this decision
- AUTO
- first element of the path is tried as the
database name - if that database doesn't exist, connect to the
default database - REQUIRED
- first element of the path is the database name
- dbname
- first element of the path is part of the service
name - connect to the database dbname
- Determine which service will handle the request
- URL PATH influences this decision
- check if a service with a name equal to the path
exists - if not, remove elements from the path until
- a match is found where URL PATH is ON or ELEMENTS
- the path is empty
19Service Determination Example
- CREATE SERVICE "a" ... URL ELEMENTS
- CREATE SERVICE "a/b" ... URL ON
- CREATE SERVICE "a/c" ... URL OFF
- http//localhost/a/d/e
- handled by "a"
- url1 "d", url2 "e"
- http//localhost/a/b/c/d
- handled by "a/b"
- url "c/d"
- http//localhost/a/c/c
- handled by "a" (not "a/c" since URL is OFF)
- url1 "c", url2 "c"
20Parameter Handling
- Parameters are supplied as
- part of the URL (URL ON ELEMENTS )
- part of the explicit parameter list (e.g,
http//localhost/service?xy) - part of the POST data
- part of the SOAP request
- Parameters are declared by specifying host
variables - CREATE SERVICE ... AS CALL foo( bar )
- The value of the parameter bar is passed as the
first parameter to the procedure foo
21Functions and System Procedures
- http_header( name )
- gets the value of an http request header
- next_http_header( name )
- gets the next http request header name
- useful for iterating over request headers
- dbo.sa_set_http_header( name, value )
- sets the value of an http response header
- dbo.sa_set_http_option( name, value )
- sets the value of an http option
- http_variable( name , i )
- gets the ith value of the named host variable
- next_http_variable( name )
- gets the next http host variable name
- useful for iterating over host variables
22Functions and System Procedures
- Example Iterate over all variables
- declare var_name varchar(250)declare var_value
long varchardeclare i intset var_name
next_http_variable( NULL )WHILE var_name is not
NULL LOOP set i 1 set var_value
http_variable( var_name, i ) WHILE var_value
is not NULL LOOP // var_value is i'th input
variable named var_name set i i 1
set var_value http_variable( var_name, i )
END LOOP var_name next_http_variable(
var_name )END LOOP
23iAnywhere Solutions at TechWave2003
Activities for iAnywhere Solutions
- Ask the iAnywhere Experts on the Technology
Boardwalk - Drop in during exhibit hall hours and have all
your questions answered by our technical experts! - Appointments outside of exhibit hall hours are
also available to speak one-on-one with our
Senior Engineers. Ask questions or get your
yearly technical review ask us for details - m-Business Pavilion
- Visit the m-Business Pavilion in the exhibit hall
to see how companies like Intermec have built
m-Business solutions using iAnywhere Solutions
technology - Wi-Fi Hotspots brought to you by Intel
iAnywhere Solutions - You can enjoy wireless internet access via a
Wi-Fi hotspot provided by Intel and iAnywhere
Solutions. Using either a laptop or PDA that is
Wi-Fi 802.11b wirelessly-enabled, visitors can
access personal email, the internet, and
"TechWave To Go", a My AvantGo channel providing
up-to-date information about TechWave classes,
events and more.
24iAnywhere Solutions at TechWave2003
Activities for iAnywhere Solutions
- Developer Community
- A one-stop source for technical information!
- Access to newsgroups,new betas and code samples
- Monthly technical newsletters
- Technical whitepapers,tips and online product
documentation - Current webcast,class,conference and seminar
listings - Excellent resources for commonly asked questions
- All available express bug fixes and patches
- Network with thousands of industry experts
- http//www.ianywhere.com/developer/