Invoking a Web service
Explanation
Web services may be invoked by passing SOAP messages over HTTP connections. The Web services framework insulates us from the chore of manually creating SOAP messages. In this manner, the Smalltalk messaging semantics are maintained. For more on message processing, see
Web Service Handlers and Message Processing. The Web service object and the container encapsulate the notion of service location transparency. For example, it is expected that a service should be able to handle both remote message invocations (those from outside its Smalltalk image), and local message invocations (those from inside the same image). Therefore, after a service is found in the container, messages dispatched to the service follow the pattern described below:
• If the ultimate receiver of the message resides within the same image, a Smalltalk directed message is sent to the service implementation.
• If the receiver of the message is outside the image, the service utilizes the SOAP stack and sends the request over the wire.
Example Smalltalk Service
Local Invocation
The code example below first locates the container which was created when the insurance policy web service was deployed earlier. It then locates the insurance policy web service in that container and invokes it. The namespace used, http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface-impl, is defined in the deployment descriptor.
[ | aContainer aService |
aContainer := SstWSContainer containerNamed: SciSocketManager default getHostName.
aService := aContainer
serviceNamed: 'SstWSInsurancePolicyInterface'
inNamespace: 'http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface-impl'.
aService about inspect ] fork.
In the code example above, the service invokes the 'about' operation locally because information regarding the service implementer was included in the service deployment descriptor used to deploy the service. This code could be altered to invoke any other service provided by the insurance policy web service.
Simulated Remote Invocation
The example below demonstrates how to simulate remote invocation of the operation by using a separate Web services container. The use of multiple Web services containers is recommended for testing purposes only. Do not use multiple containers in your deployed runtime applications.
The code snippet deploys the insurance policy web service tinto a separate container. The WSDL implementation document is used to specify the web service being deployed.
[ | aContainer aServiceCollection aService |
aContainer := SstWSContainer containerNamed: 'ClientContainer'
ifNone: [SstWSContainer createContainerNamed: 'ClientContainer'].
aServiceCollection := aContainer deploy:
'http://vasthost:9999/SstWSInsurancePolicyInterface.wsdl'.
aService := aServiceCollection first.
aService about inspect ] fork.
In the code example above, the service invokes the 'about' operation remotely utilizing SOAP messages. This code could be altered to invoke any other service provided by the insurance policy web service.
Invoking a third party service
You are not just limited to invoking services implemented in Smalltalk. To access a third party service as a client from a Smalltalk image, the image must have the Web Services feature loaded.
The Smalltalk code follows the same pattern as for remote invocation of a web service written in Smalltalk. Please note that some of these services may not be available.
Example:
[ | aContainer aServiceCollection |
“Create the container.”
SstWSContainer clearAll.
aContainer := SstWSContainer containerNamed: SciSocketManager default getHostName.
“Web service is specified by the deployment descriptor.”
aServiceCollection := aContainer deploy:
'http://www.lemurlabs.com/projects/soap/itime/ITimeService.wsdl'.
( aServiceCollection first getInternetTime ) inspect] fork.
Last modified date: 02/12/2021