|
|
This TOTD is inspired by
Learning JavaFX Script - Part 3. The original article explains how to invoke
a Web service from a JavaFX client using NetBeans 5.5.1 and GlassFish v1. Newer
version of both NetBeans and GlassFish are available since the article was
written. This TOTD (tip of the day) explains how to invoke a
Metro endpoint deployed on
GlassFish v2 from a
JavaFX client - all using
NetBeans 6.
Java Class Library" asFinish".MetroClientLibrary" as shownFinish".New",Web Service Client...".Browse..." button next to "Project"client"Finish".Build". This generates a JAR fileC:\workarea\samples\javafx\MetroClientLibrary\dist\MetroClientLibrary.jar.New Project" and entering the valuesNext >" and enter the values as shown below:Finish".Properties",Libraries", "Add JAR/Folder" and select theMetroClientLibrary" project as shownOK".metroclient.Main.fx file, replace "// place
your code hereimport java.lang.*;<br>
import javafx.ui.*;<br>
<br>
import client.NewWebServiceService;<br>
import client.NewWebService;<br>
<br>
class InputModel {<br>
attribute name: String?;<br>
}<br>
var inputModel = InputModel { };<br>
var nameField = TextField { };<br>
nameField.action = operation() {<br>
inputModel.name = nameField.value;<br>
};<br>
<br>
class ButtonClickModel {<br>
attribute result: String;<br>
}<br>
var model = new ButtonClickModel();<br>
<br>
Frame {<br>
title: "JavaFX Client -> Metro endpoint"<br>
width: 350<br>
height: 200<br>
content: GridPanel {<br>
rows: 3<br>
vgap: 5<br>
cells:<br>
[SimpleLabel {<br>
text: "Name :
"<br>
},<br>
nameField,<br>
SimpleLabel {<br>
text: "Result
from endpoint : "<br>
},<br>
Label {<br>
text: bind "{model.result}"<br>
},<br>
Button {<br>
text: "Invoke
Web Service!"<br>
action:
operation() {<br>
do {<br>
try {<br>
var service: NewWebServiceService = new NewWebServiceService();<br>
var port: NewWebService = service.getNewWebServicePort();<br>
var name: String = "{nameField.value}";<br>
var result: String = port.sayHello(name);<br>
System.out.println("response: {result}");<br>
model.result = result;<br>
} catch (e:Exception) {<br>
System.out.println("exception: {e}");<br>
}<br>
}<br>
}<br>
}<br>
]<br>
}<br>
visible: true<br>
};MetroClient")Run Project". The following window isDuke" in the text box and click on "Invoke
Web Service!After following these steps, you have created a JavaFX client that can invoke
a Metro endpoint project deployed on GlassFish - all using NetBeans IDE.
Now Metro provides secure, reliable, transactional and .NET 3.0 interoperable
Web service. Have you tried/used any of those features in Metro ?
Please leave suggestions on other TOTD that you'd like to see. A complete
archive is available here.
Technorati: totdd
javafx
metro
glassfish
netbeans
webservices