Learning objectives By completing this module, you will:
Learn how WSDL definitions are reflected in NexJ messages.
Learn how to extend a class model to include a web service.
Reinforce your knowledge about creating a channel.
Reinforce or introduce some Presentation layer knowledge.
Prerequisite: The SOA service created in the previous lesson.
Key concepts
WSDL is a standard XML format for describing XML web services that define the set of operations and messages that can be sent to and received from a given web service.
In this learning module, we add an attribute that gets its value from a web service call to the Person class. An input value of City is passed to the service, and a response message is returned with the temperature. This can then be optionally displayed in the user interface, demonstrating how you can quickly integrate with external non-relational data sources.
Importing the WSDL definition
To simplify interacting with the web service, we create message definitions by importing the WSDL definition.
Learning activity
To import the WDSL definition:
From the File menu, select Import.
In the Import dialog, select NexJ Studio > XML Schema/WSDL and click Next.
In the File paths or URLs field, enter http://localhost:7080/training/soa/training:weather:1.0/soap?wsdl and click Next.
In the Message Prefix field, enter Weather_.
Leave all checkboxes unchecked, and click Finish.
In the Integration layer, select the Messages tab.
A number of new messages with names that start with "Weather_" have been created. To see only these new messages, type Weather in the Search field.
Double-click the Weather_getWeather message to open it and review the source. Note that the expected input is a cityName.
Open the Weather_getWeatherResponse message and review the outputs that come back as a response.
Creating a new channel for integration
You are now ready to set up for accessing the web service through a channel. You'll need to create a new channel for the web service and add it to the environment.
Learning activity
To create a new channel:
In the Integration layer, select the Channels tab.
The code sends a message to the web service that includes the ZIP code for the entity's default address. The response is formatted when it is received.
In the Entity class, go to the Attributes tab of the class editor and add a new attribute. This is a calculated attribute that contains the formatted response from the web service.
Name: currentWeather
Type: string
In the Value tab for this attribute, set the value to (this'fetchCurrentWeather).
Save your work.
Testing the web service integration
Write a Scheme script that creates a Person with an address, and then fetches the person's current weather through the web service.
Learning activity
To test the web service integration:
Use an existing scratchpad or create a new one, and add the following code:
SCHEME
(define FIRST "Tim")
(define LAST "Lamont")
; Read the person
(define thePerson (read-instance Person '() (quasiquote (and (=
firstName ,FIRST) (= lastName ,LAST))) #f))
; If the person doesn't exist, create it
(if (null? thePerson)
(begin
(set! thePerson (Person'createEntity "Contact" (: firstName FIRST) (:
lastName LAST)))
(Address'createFactory
thePerson
(read-instance AddressType '() '(= name "Home") #f)
(: address1 "Lamont Tower")
(: address2 "1997 Orphan Road")
(: city "Toronto")
(: state "ON")
(: country "CA")
(: zip "M4A E3T")
)
(commit)
)
)
; Fetch the person's weather
(thePerson'currentWeather)
Save the scratchpad.
Run the Server Console.
Execute each statement of the scratchpad in the Server Console and review the results.
Stop the Console.
Testing the updated application
Learning activity
To test the updated application:
Start your server.
Load http://localhost:7080/training/ui/portal in your browser.
Navigate to the Contacts workspace.
The weather information should appear in the Contact Navigator.
JavaScript errors detected
Please note, these errors can depend on your browser setup.
If this problem persists, please contact our support.