se 370: programming web services week 4: soap & netbeans copyright © steven w. johnson february...
TRANSCRIPT
![Page 1: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/1.jpg)
SE 370: Programming Web Services
Week 4: SOAP & NetBeansCopyright © Steven W. Johnson
February 1, 2013
![Page 2: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/2.jpg)
SOAP-based web services
Nusoap
SOAP web services in:
PHP
NetBeans (Java)
This week:
2
![Page 3: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/3.jpg)
Client has limited alternatives:
data is a single value
data is an array
data has multiple values (SOAP)
data is constants (written into the code)
data is variables (collected from a form)
Conceptual web services:
3
![Page 4: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/4.jpg)
Server has limited number of alternatives:
simple calculation/print text (‘Hello World’)
complex calculation using many variables
writes query using variables; database
read/update operation to a table
return single variable
return an array
Conceptual web services:
4
![Page 5: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/5.jpg)
Conceptual web services:
5
server
serialize de-serialize
client
Data appears as: single value array function parameters
Data collected by: constants in code dorm inputs document
Data processed: simple single calculation complex calculation prepare data as a query
Data used by: function query/database table
Data transferred as: variable array
![Page 6: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/6.jpg)
SOAP:
6
Last week, XML-RPC; this week, SOAP
XML-RPC is the BASIC of web services
SOAP is the C of web services
Rules
Structure
Format
![Page 7: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/7.jpg)
SOAP:
7
SOAP more verbose; more capable
SOAP is about document transfer
SOAP requires an IDE
If you like polymorphic accessors, enumerations,and orthogonal protocol binding, then SOAP is for you
![Page 8: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/8.jpg)
SOAP:
8
SOAP adds to XML-RPC:
user-defined data types
specify recipient
message specific processing control
others
NOT (as) easy to use
Biggest advantage: customization of message
![Page 9: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/9.jpg)
SOAP:
9
SOAP: Simple Object Access Protocol
Platform and language independent
HTTP and XML, like XML-RPC
Difference: files instead of data
Supports different protocols and formats:HTTP, SMTP, MIME
W3C recommendation (2003)
≈44 pages long (not so short)
![Page 10: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/10.jpg)
Ways to use SOAP:
HTTP
FTP
I/O
Jabber
SMTP
POP3
TCP
MQSeries
SOAP:
10
![Page 11: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/11.jpg)
Has three elements:
<envelope>
<header>
<body>
may include fault element
CANNOT contain a DTD reference
CANNOT hold XML processing instructions
SOAP:
11
![Page 12: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/12.jpg)
SOAP:
12
SOAP skeleton:
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Header>...</soap:Header>
<soap:Body>... <soap:Fault> ... </soap:Fault></soap:Body>
</soap:Envelope>
http://www.w3schools.com/soap/soap_envelope.asp
![Page 13: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/13.jpg)
SOAP:
13
SOAP header:
Optional; first child of Envelope if present
Holds application-specific information
Defines how to process SOAP message
three defined attributes to default namespace:
mustUnderstand
Actor
encodingStyle
![Page 14: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/14.jpg)
SOAP:
14
SOAP envelope:
root element of SOAP message
holds one body element
SOAP body element: held in envelope<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m="http://www.example.org/stock"> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body></soap:Envelope>
![Page 15: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/15.jpg)
Nusoap:
15
Used with PHP; a collection of PHP classes
Allows rpc/encoded & document/literal services
Has some similarites with XML-RPC
Dietrich Ayala
![Page 16: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/16.jpg)
‘nusoap’ is the library (collection of PHP classes)
Converts PHP into XML (SOAP envelopes)
SOAP 1.1, WSDL 1.1, and HTTP 1.0/1.1
Version 1.114 (2007)
Nusoap:
16
![Page 17: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/17.jpg)
The process:
Nusoap:
17
![Page 18: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/18.jpg)
Again, three files are used: client, server, library
All files placed in web folder
Nusoap:
18
www
client.php
server.php
nusoap.php (SOAP library)
![Page 19: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/19.jpg)
Nusoap:
19
server
Nusoap
client
Nusoap
serialize de-serialize
![Page 20: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/20.jpg)
Create ‘client.php’ in Dreamweaver:
Prints ‘Hello Scott’ to web page
Nusoap:
20
<?php require_once('nusoap.php'); $client = new nusoap_client('http://127.0.0.1/server.php'); $result = $client->call('hello', array('name' => 'Scott')); echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';?>
Uses ‘hello’ function
Sends data
Absolute address
![Page 21: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/21.jpg)
Create ‘server.php’ in Dreamweaver:
Nusoap:
21
<?php require_once('nusoap.php'); $server = new soap_server; $server->register('hello');
function hello($name) { return 'Hello, ' . $name; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);?>
if
![Page 22: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/22.jpg)
Lab: Nusoap
22
POST /server.php HTTP/1.0 Host: 127.0.0.1 User-Agent: NuSOAP/0.7.3 (1.114) Content-Type: text/xml; charset=ISO-8859-1 SOAPAction: "" Content-Length: 500
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body> <ns5932:hello xmlns:ns5932="http://tempuri.org"> <name xsi:type="xsd:string">Scott</name> </ns5932:hello></SOAP-ENV:Body></SOAP-ENV:Envelope>
Request: header/xml generated by ‘client’
![Page 23: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/23.jpg)
Response: header/xml generated by ‘server’
Lab: Nusoap
23
HTTP/1.1 200 OK Date: Fri, 15 Mar 2013 13:38:22 GMT Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o PHP/5.3.3 DAV/2 X-Powered-By: PHP/5.3.3 X-SOAP-Server: NuSOAP/0.7.3 (1.114) Content-Length: 518 Vary: User-Agent,Accept-Encoding Connection: close Content-Type: text/xml; charset=ISO-8859-1
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body> <ns1:helloResponse xmlns:ns1="http://tempuri.org"> <return xsi:type="xsd:string">Hello, Scott</return> </ns1:helloResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
![Page 24: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/24.jpg)
‘client’ calls ‘server’ for processing of data:
Processing function can be much more complex
Lab: Nusoap
24
<?php require_once('nusoap.php'); $client = new nusoap_client('http://127.0.0.1/server.php'); $result = $client->call('hello', array('name' => 'Scott')); echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';?> <?php
require_once('nusoap.php'); $server = new soap_server; $server->register('hello');
function hello($name) { return 'Hello, ' . $name; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);?>
“Scott”
$name = “Scott”
![Page 25: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/25.jpg)
Copy/paste ‘nusoap’ into your web server
Fix the URL, change name to your name
Open page: localhost/nusoap/client.php
Lab: Nusoap
25
![Page 26: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/26.jpg)
Copy/paste ‘dice’ into your web server
Holds:
client
server
library
6 images of a die (zar)
Lab: Dice
26
![Page 27: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/27.jpg)
Working page:
Lab: Dice
27
![Page 28: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/28.jpg)
Code required (server):
ignore the passed variable (eliminate??)
return is an array, must define
random number generator: (returns int)
Lab: Dice
28
mt_rand(1,6); //more efficientrand(1,6);
$client->call('hello');
$result = [];
3.png125px x 125px
![Page 29: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/29.jpg)
Code required (client):
function arguments = parameters
remove messages
add form, images, text output
Lab: Dice
29
<img src="<?php echo $result[0]; ?>.png" width="125" height="125"><img src=" 1 .png" width="125" height="125">
![Page 30: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/30.jpg)
Done!
Lab: Dice
30
![Page 31: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/31.jpg)
Client code (PHP):
Lab: Dice
31
<?phpif(isset($_POST['button'])) {
require_once('nusoap.php'); $client = new nusoap_client('http://127.0.0.1/dice/server.php');
$err = $client->getError(); // Check for an error if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; }
$result = $client->call('hello'); }?>
![Page 32: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/32.jpg)
32
<!DOCTYPE html><html> <head> <style> table {
margin-left: auto; margin-right: auto; }
</style> </head> <body> <p> </p> <form name=“RollDice" method="post" action=""> <table width="350" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="175" height="125"><div align="center"> <img src="<?php echo $result[0]; ?>.png" width="125" height="125"></div> </td> <td width="175" height="125"><div align="center"> <img src="<?php echo $result[1]; ?>.png" width="125" height="125"></div> </td> </tr> <tr> <td height="63" colspan="2"><div align="center"> <input type="submit" name="button" id="button" value="Roll the Dice"></div> </td> </tr> <tr> <td height="63" colspan="2"><div align="center"><h2>Your spin = <?php echo $result[0] + $result[1]; ?></h2> </div> </td> </tr> </table> </form> <p> </p> </body></html>
![Page 33: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/33.jpg)
Server code (PHP):
Lab: Dice
33
<?php // Pull in the NuSOAP code require_once('nusoap.php'); // Create the server instance $server = new soap_server; // Register the method to expose $server->register('hello'); // Define the method as a PHP function function hello() {
$result = []; $result[0] = mt_rand(1, 6);
$result[1] = mt_rand(1, 6);return $result;
} // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);?>
![Page 34: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/34.jpg)
Break 34
![Page 35: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/35.jpg)
SOAP best built in IDE
Our IDE: NetBeans, IDE for Java programming*
Default: UniServer isn’t Java enabled
Time for new web stack
NetBeans:
35
Programming Language
Web Server
Database
Language Engines
Operating System
![Page 36: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/36.jpg)
NetBeans: IDE for Java programming*
Download: http://netbeans.org/downloads/
NetBeans 7.3 (64-bit) includes:
GlassFish (application & web server)
Apache Tomcat 7.0.34 (Java servlets)
NetBeans:
36
![Page 37: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/37.jpg)
An open source IDE
Primary aim: Java
Supports:
HTML/5, PHP, C/C++, etc.
Started as a school project
Purchased by Sun
Purchased by Oracle
What is NetBeans?
37
![Page 38: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/38.jpg)
Java Programming environment:
Java Server Pages (replaces PHP)
Tomcat
Glassfish server (Replaces Apache)
NetBeans:
38
![Page 39: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/39.jpg)
Java Server Pages
Serves same function as .php and .asp
Java is compiled
NetBeans:
39
![Page 40: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/40.jpg)
All three:
are server side technologies
allow scripting to be mixed HTML
require server software (compiler/interpreter)
ASP and JSP may require application server
JSP is an extension on a web page; uses servlets
PHP is a programming language; uses scripts
NetBeans:
40
![Page 41: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/41.jpg)
Biggest differences:
strictly data typed
requires an application server (compiler)
<% %>instead of <? ?>
NetBeans:
41
<h2>Some even numbers:</h2> <% int loop = 1; for (int i=0; i<11; i+=2) { %> <p>Even number <%= loop %>: <%= i %>.</p> <% } %> <p>Done.</p>
![Page 42: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/42.jpg)
GlassFish:
an application server
also serves web pages
open source
manages JavaEE applications
NetBeans:
42*many IDEs offer support in many programming paradigms
![Page 43: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/43.jpg)
What’s an application server?
A server that hosts applications
PHP: interprets and then sends
appserver: runs code embedded in web pages
connect to databases
connect to middleware
provides methods clients can call
.asp and .jsp are big users
NetBeans:
43*many IDEs offer support in many programming paradigms
![Page 44: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/44.jpg)
What’s an application server?
NetBeans:
44
receives request
sends response
data/method calls
sends output
creates or locates htmlmethod of communication: httpinformation passed: markup
compiles executables/run processesmethod of communication: anythinginformation passed: program logic
Web Server
Application Server
![Page 45: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/45.jpg)
Tomcat: Servlet container
Made by Apache
Open source web server
Components:
Catalina: servlet container
Coyote: HTTP connector
Jasper: a JSP engine (compiler)
NetBeans:
45*many IDEs offer support in many programming paradigms
![Page 46: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/46.jpg)
Compiles servlets on .jsp
Effect: like PHP interpreter for Java
NetBeans:
46
Web Server
Web Server
Servlet Container
HTTP Request
HTTP Response
Client
![Page 47: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/47.jpg)
NetBeans 7.4 (windows) includes JDK
Start Extract:
Installing NetBeans:
47
![Page 48: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/48.jpg)
Start Install:
Installing NetBeans:
48
![Page 49: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/49.jpg)
Do lots of thinking and installing
Place shortcut in Quick Launch
Installing NetBeans:
49
![Page 50: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/50.jpg)
Close start page
Installing NetBeans:
50
![Page 51: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/51.jpg)
Editor good for single-file solutions
IDE good when solutions require several files
Example: C code
source code
libraries
object files
linker files
executable
IDE versus editor:
51
![Page 52: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/52.jpg)
Projects:
Holds all files necessary for integrated solution
“A folder” holding a multi-file solution
A workspace holds many projects
Projects hold many folders/files that complete a task
IDE versus editors:
52
![Page 53: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/53.jpg)
Create a new project: ‘test’ (.html)
NetBeans:
53
![Page 54: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/54.jpg)
NetBeans:
54
![Page 55: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/55.jpg)
Create a new project: ‘test’ (.jsp)
NetBeans:
55
![Page 56: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/56.jpg)
NetBeans:
56
![Page 57: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/57.jpg)
Right click on Project name and ‘run’
NetBeans:
57
![Page 58: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/58.jpg)
Check your ‘Output’ panel
NetBeans:
58
![Page 59: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/59.jpg)
Start GlassFish manually (ONLY if needed):
Services window
Right-click server node
Start
NetBeans:
59
![Page 60: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/60.jpg)
Unblock the port for Java
SOAP web services & NetBeans:
60
![Page 61: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/61.jpg)
Generates a blank web page (port :8080)
NetBeans:
61
![Page 62: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/62.jpg)
Two instances of Java running (after run)
One instance of NetBeans
SOAP web services & NetBeans:
62
![Page 63: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/63.jpg)
Running netstat –ao to check ports:
SOAP web services & NetBeans:
63
![Page 64: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/64.jpg)
PID of ports goes to ‘big Java’
SOAP web services & NetBeans:
64
![Page 65: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/65.jpg)
If GlassFish doesn’t start…
Turkish locale seems to be an issue
SOAP web services & NetBeans:
65
![Page 66: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/66.jpg)
Netbeans_default_options
Add to end:
SOAP web services & NetBeans:
66
"-J-Duser.language=en -J-Duser.region=US"
![Page 67: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/67.jpg)
Location of saved work:
NetBeans:
67
![Page 68: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/68.jpg)
Holds all files necessary for integrated solution
“A folder” holding a multi-file solution
A workspace holds many projects
Projects hold many folders/files that complete a task
Projects:
68
![Page 69: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/69.jpg)
Open NetBeans: (wizard approach)
File – New Project
Categories: “Java Web”
Projects: “Web Application”
Next
Hello NetBeans web service:
69http://javapapers.com/web-service/soap-web-service-introduction/
![Page 70: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/70.jpg)
Project name: “HelloNetBeans” (folder name)
Next
70
Hello NetBeans web service:
![Page 71: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/71.jpg)
Accept default settings
Finish
71http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 72: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/72.jpg)
‘Client’ page is generated (index.jsp)
72http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 73: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/73.jpg)
Right-click project, run (test the .jsp file)
73http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 74: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/74.jpg)
Right click on project name
New – Web Service (order probably different)
74
Hello NetBeans web service:
![Page 75: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/75.jpg)
Web Service Name: ‘HelloWorld’
Package: ‘com.javapapers.webservice’
Finish
75http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 76: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/76.jpg)
HelloNetBeans.java (service code)
76
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.javapapers.webservice;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.jws.WebParam;
/** * * @author Steve */@WebService(serviceName = "Hello")public class Hello {
/** * This is a sample web service operation */ @WebMethod(operationName = "hello") public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; }}
Hello NetBeans web service:
![Page 77: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/77.jpg)
Next step, update the .wsdl
View the current .wsdl: (works in IE, Chrome)
http://localhost:8080/HelloNetBeans/Hello?wsdl
77http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 78: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/78.jpg)
78
Hello NetBeans web service:
![Page 79: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/79.jpg)
Next step, set up ‘client’ (index.jsp)
Remove text “Hello World”
79http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 80: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/80.jpg)
Right click on project name
Choose: New – ‘Web Service Client…’
80
Hello NetBeans web service:
![Page 81: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/81.jpg)
WSDL URL: http://localhost:8080/HelloNetBeans/Hello?
wsdl
Package: com.javapapers.webserviceclient
Click ‘finish’; project rebuilt
‘localhost’ okay
81
Hello NetBeans web service:
![Page 82: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/82.jpg)
Right click on .jsp page
Select ‘Web Service Client Resources’
Select ‘Call Web Service Operation…’
82
Hello NetBeans web service:
![Page 83: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/83.jpg)
Select ‘Hello’ from this dialog box and ‘OK’
Expand out tree if necessary
83http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 84: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/84.jpg)
Code brings in ‘Hello’ from server file
84http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 85: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/85.jpg)
Update the text string:
‘Hello’ is text from XML
‘Steve’ is text from ‘index’
85http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 86: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/86.jpg)
Save your files
Right click on project name, run code
86
Hello NetBeans web service:
![Page 87: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/87.jpg)
Complete!
87http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 88: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/88.jpg)
Files of interest:
index.jsp (‘client’)
HelloWorld.java (‘server’)
HelloWorld.wsdl
88http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 89: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/89.jpg)
index.jsp (client):NetBeansProjects/HelloNetBeans/web/index.jsp
89
<%-- Document : index Created on : Mar 11, 2014, 10:06:36 PM Author : Steve--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1></h1> <%-- start web service invocation --%><hr/> <% try {
com.javapapers.webserviceclient.Hello_Service service = new com.javapapers.webserviceclient.Hello_Service();com.javapapers.webserviceclient.Hello port = service.getHelloPort(); // TODO initialize WS operation arguments herejava.lang.String name = "Steve";// TODO process result herejava.lang.String result = port.hello(name);out.println("Result = "+result);
} catch (Exception ex) {// TODO handle custom exceptions here
} %> <%-- end web service invocation --%><hr/> </body></html>
Hello NetBeans web service:
![Page 90: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/90.jpg)
Hello.java:NetBeansProjects/Wk4HelloWorld/src/java/com/javapapers/
webservice/Hello.java
90
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package com.javapapers.webservice;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.jws.WebParam;
/** * * @author Steve */@WebService(serviceName = "Hello")public class Hello {
/** * This is a sample web service operation */ @WebMethod(operationName = "hello") public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; }}
Hello NetBeans web service:
![Page 91: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/91.jpg)
HelloWorld.wsdl:NetBeansProjects/Wk4HelloWorld/build/web/WEB-INF/
wsdl/localhost_8080/HelloNetBeans/Hello.wsdl
91
<?xml version='1.0' encoding='UTF-8'?><!-- lots of legalese -->
<types><xsd:schema><xsd:import namespace="http://webservice.javapapers.com/" schemaLocation="http://localhost:8080/Wk4HelloWorld/HelloWorld?xsd=1"/></xsd:schema></types><message name="hello"><part name="parameters" element="tns:hello"/></message><message name="helloResponse"><part name="parameters" element="tns:helloResponse"/></message><portType name="HelloWorld"><operation name="hello"><input wsam:Action="http://webservice.javapapers.com/HelloWorld/helloRequest" message="tns:hello"/><output wsam:Action="http://webservice.javapapers.com/HelloWorld/helloResponse" message="tns:helloResponse"/></operation></portType>
Hello NetBeans web service:
![Page 92: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/92.jpg)
HelloWorld.wsdl:NetBeansProjects/Wk4HelloWorld/build/web/WEB-INF/
wsdl/localhost_8080/Wk4HelloWorld/HelloWorld.wsdl
92
<binding name="HelloWorldPortBinding" type="tns:HelloWorld"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="hello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="HelloWorld"><port name="HelloWorldPort" binding="tns:HelloWorldPortBinding"><soap:address location="http://localhost:8080/Wk4HelloWorld/HelloWorld"/></port></service></definitions>
http://javapapers.com/web-service/soap-web-service-introduction/
Hello NetBeans web service:
![Page 93: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/93.jpg)
1. SOAP messages are defined using an:
A. XML DTDB. XML SchemaC. XSLTD. XML CSS
Quiz:
93
![Page 94: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/94.jpg)
2. XML-RPC compared to SOAP:
A. Is easier and more powerfulB. Is easier and less powerfulC. Is more complex and more powerfulD. Is more complex and less powerful
Quiz:
94
![Page 95: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/95.jpg)
3. An XML-RPC message compared to a SOAP message:
A. The XML-RPC message is smaller and carries more dataB. The XML-RPC message is larger and cards more dataC. The SOAP message is larger and carries more dataD. The SOAP message is larger and it carries less data
Quiz:
95
![Page 96: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/96.jpg)
4. Comparing XML-RPC to SOAP:
A. XML-RPC allows for the message to be customized B. SOAP allows for the message to be customizedC. XML-RPC is sent using HTTP only D. SOAP is sent using HTTP only
Quiz:
96
![Page 97: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/97.jpg)
5. XML-RPC and SOAP:
A. XML-RPC can be made in NotepadB. SOAP can be made in NotepadC. Both must be made using an IDE
Quiz:
97
![Page 98: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/98.jpg)
6. Java Server Pages (JSP):
A. Are a web services technologyB. Are a client-side technologyC. Are a server-side technologyD. Allow scripting to be mixed with HTMLE. Scripts are executed before the page is renderedF. Scripts are executed after the page is rendered
Quiz:
98
![Page 99: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/99.jpg)
7. An application server:
A. Inserts the output from scripts into HTML contentB. Inserts the output from compiled code into HTML contentC. Executes compiled code on the client machineD. Executes scripted code on the client machine
Quiz:
99
![Page 100: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/100.jpg)
SE 370: Programming Web Services
Week 4: SOAP & NetBeansCopyright © Steven W. Johnson
February 1, 2013
![Page 101: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/101.jpg)
101
Build a more complete service
Build ‘client’:
pass 2 integers to ‘server’
answer displayed on web page
more customized approach (less “wizardy”)
Lab: AddNumbers
![Page 102: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/102.jpg)
102
Create the project:
Lab: AddNumbers
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
![Page 103: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/103.jpg)
103
Rt. click on project name – New – web service
Creates the *.java page (Name = filename)
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: AddNumbers
![Page 104: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/104.jpg)
104
Lab: AddNumbers/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package com.steve.johnson.add;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.jws.WebParam;
/** * * @author Steve */@WebService(serviceName = "AddingMachine")public class AddingMachine {
/** * This is a sample web service operation */ @WebMethod(operationName = "hello") public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; }}
![Page 105: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/105.jpg)
105
Run the .jsp file
Lab: AddNumbers
![Page 106: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/106.jpg)
106
Now, new begins. Click on ‘Design’
Lab: AddNumbers
![Page 107: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/107.jpg)
107
Modify ‘server’ method
@WebMethod(operationName = "hello") public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; }}
Lab: AddNumbers
![Page 108: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/108.jpg)
108
Click ‘Add Operation…’
Lab: AddNumbers
![Page 109: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/109.jpg)
109
Name = method name and method return type
Arguments used by the method and data types
Lab: AddNumbers
![Page 110: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/110.jpg)
110
Method is built
@WebMethod(operationName = "Adder")public int Adder(@WebParam(name = "one") int one, @WebParam(name = "two") int two) { //TODO write your implementation code here: return 0; }
@WebMethod(operationName = "Adder")public int Adder(@WebParam(name = "one") int one, @WebParam(name = "two") int two) { //TODO write your implementation code here: return one + two; }
Lab: AddNumbers
![Page 111: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/111.jpg)
111
Select ‘hello’ and ‘Remove Operation’
Lab: AddNumbers
![Page 112: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/112.jpg)
112
Right click on project and deploy
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: AddNumbers
![Page 113: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/113.jpg)
113
Test web Service
Lab: AddNumbers
![Page 114: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/114.jpg)
114
Lab: AddNumbers
![Page 115: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/115.jpg)
115
Rt click on project - New – Web Service Client…
Lab: AddNumbers
![Page 116: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/116.jpg)
116
Click on Browse button for Project
Browse in wsdl
Lab: AddNumbers
![Page 117: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/117.jpg)
117
Add a different package name at bottom
Finish
Lab: AddNumbers
![Page 118: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/118.jpg)
118
Go to index.jsp file
Right click in Source Window,
Web Service Client – Web Service Operation
Lab: AddNumbers
![Page 119: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/119.jpg)
119
Drill down method on .java page
OK
Lab: AddNumbers
![Page 120: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/120.jpg)
120
Change the ‘int’ variables to values
Lab: AddNumbers
![Page 121: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/121.jpg)
121
Delete ‘Hello World’
Save page
Right-click in window and Run File
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: AddNumbers
![Page 122: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/122.jpg)
122
Output generated:
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: AddNumbers
![Page 123: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/123.jpg)
123
Use text fields to get data
One text field, one int field
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: Adult
![Page 124: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/124.jpg)
124
Create the project:
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: Adult
![Page 125: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/125.jpg)
125
Open the Palette (Ctrl + Shift + 8)
Window – IDE Tools – Palette
Drag-and-drop support, no WYSIWYG yet
Lab: Adult
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> </body></html>
![Page 126: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/126.jpg)
126
Change title to “Age Status”
Delete <h1> element
Lab: Adult
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> </body></html>
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Age Status</title> </head> <body> </body></html>
![Page 127: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/127.jpg)
127
Need four elements?
form
table?
2 text fields
1 submit button
Rules of HTML are the same in .jsp as .php
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: Adult
![Page 128: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/128.jpg)
128
Lab: Adult <form name="Data" method="POST"></form><form name="Data" method="POST"> <table border="0" width="250"> <thead> <tr> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> </tbody> </table></form>
Create form
Create table
![Page 129: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/129.jpg)
129
Lab: Adult
<tr> <td></td> <td><input type="text" name="Name" value="" /></td> </tr> <tr> <td></td> <td><input type="text" name="Age" value="" /></td> </tr> <tr> <td></td> <td></td> </tr> </tbody> </table></form>
Add text fields:
![Page 130: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/130.jpg)
130
Lab: Adult
<tr> <td>Name:</td> <td><input type="text" name="Name" value="" /></td> </tr> <tr> <td>Age:</td> <td><input type="text" name="Age" value="" /></td> </tr> <tr> <td></td> <td></td> </tr> </tbody> </table></form>
Add labels: (manually enter)
![Page 131: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/131.jpg)
131
Lab: Adult
<tr> <td>Name:</td> <td><input type="text" name="Name" value="" /></td> </tr> <tr> <td>Age:</td> <td><input type="text" name="Age" value="" /></td> </tr> <tr> <td></td> <td><input type="submit" value="Check" name="Submit" /></td> </tr> </tbody> </table></form>
Add submit button:
![Page 132: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/132.jpg)
132
Lab: AdultCheck work: save and run the page
Names of elements shown on page
NameAge
Submit
![Page 133: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/133.jpg)
133
Lab: AdultBuild the web service
Rt. Click on project name – New – Web Service
![Page 134: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/134.jpg)
134
Lab: Adult
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package com.steve.johnson.adult;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.jws.WebParam;
/** * * @author Steve */@WebService(serviceName = "AdultMinor")public class AdultMinor {
/** * This is a sample web service operation */ @WebMethod(operationName = "hello") public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; }}
AdultMinor.java
![Page 135: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/135.jpg)
135
Update the web service method
Lab: Adult
![Page 136: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/136.jpg)
136
Click ‘Add Operation…’
Lab: Adult
![Page 137: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/137.jpg)
137
Name = method name and method return type
Arguments used by the method and data types
Lab: Adult
![Page 138: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/138.jpg)
138
Select ‘hello’ and ‘Remove Operation’
Lab: Adult
![Page 139: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/139.jpg)
139
Right click on project and deploy
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: Adult
![Page 140: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/140.jpg)
140
Re-run index.java
http://www.roseindia.net/webservices/netbeans/Web-Service.shtml
Lab: Adult
![Page 141: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/141.jpg)
141
AdultMinor.java:
Lab: Adult
package com.steve.johnson.adult;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.jws.WebParam;
/** * * @author Steve */@WebService(serviceName = "AdultMinor")public class AdultMinor {
/** * Web service operation */ @WebMethod(operationName = "AgeTest") public String AgeTest(@WebParam(name = "Name") String Name, @WebParam(name = "Age") int Age) { //TODO write your implementation code here: return null; }}
![Page 142: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/142.jpg)
142
Fix the ‘AgeTest’ method:
Lab: Adult
/** * Web service operation */ @WebMethod(operationName = "AgeTest") public String AgeTest(@WebParam(name = "Name") String Name, @WebParam(name = "Age") int Age) { if (Age < 18) {return Name + " is a minor";} else {return Name + " is an adult";} }}
![Page 143: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/143.jpg)
143
Save .java file and test web service
Lab: Adult
![Page 144: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/144.jpg)
144
Save .java file and test web service
Lab: Adult
![Page 145: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/145.jpg)
145
Save .java file and test web service
Lab: Adult
![Page 146: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/146.jpg)
146
Rt click on project - New – Web Service Client…
Lab: Adult
![Page 147: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/147.jpg)
147
Click on Browse button for Project
browse in wsdl
add a different package name
Lab: Adult
![Page 148: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/148.jpg)
148
Go to index.jsp file
Right click in Source Window,
Web Service Client – Web Service Operation
Lab: Adult
![Page 149: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/149.jpg)
149
Lab: AdultConnect the form to the web service
![Page 150: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/150.jpg)
150
Lab: AdultExtract text field values
![Page 151: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/151.jpg)
151
Lab: AdultNo ‘isset’ for the submit button
Save ‘index.jsp’
Run
![Page 152: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/152.jpg)
Break 152
![Page 153: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/153.jpg)
Create a web service that finds the average offive scores
Print that average score to a text field
Watch your data types
Assignment:
153
Score 1:
Score 2:
Score 3:
Score 4:
Score 5:
Average:Submit
![Page 154: SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013](https://reader035.vdocuments.us/reader035/viewer/2022062322/56649c7d5503460f94932940/html5/thumbnails/154.jpg)
SE 370: Programming Web Services
Week 4: SOAP & NetBeansCopyright © Steven W. Johnson
February 1, 2013