Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop web services - Invocation framework (WSIF) > Use WSIF to invoke web services > Develop a WSIF service
Use WSIF to bind a JNDI reference to a web service
We can use the Web Services Invocation Framework (WSIF) to bind a reference to a web service, then look up the reference by using JNDI.
You access a web service through information provided in the WSDL document for the service. If you do not know where to find the WSDL document for the service, but you know that it has been registered in a UDDI registry, then you look it up in the registry. Java programs access Java objects and resources in a similar manner, but using a JNDI interface.
The code fragments in the following steps show how, by using WSIF, you can bind a reference to a web service then look up the reference by using JNDI.
Procedure
- Specify the argument values for the web service.
The web service is represented in WSIF by an instance of the org.apache.wsif.naming.WSIFServiceRef class. This simple Referenceable object has the following constructor:
public WSIFServiceRef( String WSDL, String sNS, String sName, String ptNS, String ptName) { [...] }In this example
- WSDL is the location of the WSDL file containing the definition of the service.
- sNS is the full namespace for the service definition (you can specify null if only one service is defined in the WSDL file).
- sName is the local name for the service definition (you can specify null if only one service is defined in the WSDL file).
- ptNS is the full namespace for the port type within the service to use (you can specify null if only one port type is available for the service).
- ptName is the local name for the port type (you can specify null if only one port type is available for the service).
For example, if the WSDL file for the web service is available from the web address http://myServer/WSDL/Example.WSDL and contains the following service and port type definitions:
<definitions targetNamespace="http://hostname/namespace/example" xmlns:abc="http://hostname/namespace/abc" [...] <portType name="ExamplePT"> <operation name="exampleOp"> <input name="exampleInput" message="tns:ExampleInputMsg"/> </operation> </portType> [...] <service name="abc:ExampleService"> [...] </service> [...] </definitions>We can specify the following argument values for the WSIFServiceRef class:
- WSDL is http://myServer/WSDL/Example.WSDL
- sNS is http://hostname/namespace/abc
- sName is ExampleService
- ptNS is http://hostname/namespace/example
- ptName is ExamplePT
- Bind the service by using JNDI.
To bind the service reference in the naming directory by using JNDI, you can use the com.ibm.websphere.naming.JndiHelper class in WAS:
[...] import com.ibm.websphere.naming.JndiHelper; import org.apache.wsif.naming.*; [...] try { Context startingContext = new InitialContext(); WSIFServiceRef ref = new WSIFServiceRef("http://myServer/WSDL/Example.WSDL", "http://hostname/namespace/abc" "ExampleService", "http://hostname/namespace/example", "ExamplePT"); JndiHelper.recursiveRebind(startingContext, "myContext/mySubContext/myServiceRef", ref); } catch (NamingException e) { // Handle error. } [...]- Look up the service by using JNDI.
The following code fragment shows the lookup of a service by using JNDI:
[...] try { [...] InitialContext ic = new InitialContext(); WSIFService myService = (WSIFService) ic.lookup("myContext/mySubContext/myServiceRef"); [...] } catch (NamingException e) { // Handle error. } [...]
WSIF and WSDL
Use complex types
Link a WSIF service to the underlying implementation of the service
Interacting with the Java EE container in WAS
Run WSIF as a client
Develop a WSIF service
Use WSIF to invoke web services