When you call a Web Service, you create resources that describe the Web Service you want to call, its location, and initial inputs. Axis then takes those resources and produces from them a SOAP message that it then sends to the Web Service itself.

There are two ways to create a Web Service call:

The main distinction between the two processes is the data types they can handle. Because using Web Services requires that data be converted into several formats — from a native format into an XML representation of that format back into the native form — it is important that you choose a process designed to work with the data types accessed by the Web Services you want to employ.

The static process can handle any data type regardless of whether it’s primitive, complex, object, or non-standard. Non-standard types may require some extra effort as is the case when accessing RepositoryItems or JMS messages. The dynamic process, conversely, is limited to only working with object versions of these data types (as permitted by SOAP 1.1):

Some complex types such as Array, List, Set, and Map may be supported using the dynamic process in a restricted way. See the JAX-RPC Specification for details on data type restrictions.

The subsequent sections describe how you would make a call to the loginUser Web Service following the static and dynamic processes.

Creating a Call Using a Client Stub (Static)

When you create a call following the static method, you represent the server-side Web Service architecture on the client by creating a client stub and a client:

The call is constructed by compiling information from the client stub, client, and various other supporting classes that hold static information.

For example, to create a static call to the loginUser Web Service:

  1. Create and compile the client stub, if one does not already exist for the Web Service. See Creating and Compiling a Client Stub below.

  2. Add the client stub to the CLASSPATH variable so the client stub is available to local Web Services resources.

  3. Create and compile the client. See Creating and Compiling a Client below.

  4. Use Axis to execute the Web Service call:

    loginStub.createUser(pProfileAsXML)

    The format of this call is:

    clientStub.web_service(generated_web_Service_Call_instance)

    Axis creates the XML message, wraps it in SOAP, and sends it via HTTP to the Web Service location in the client stub.

See Creating and Compiling a Client Stub and Creating and Compiling a Client.

Creating and Compiling a Client Stub

The client stub describes the Web Service method and supporting resources in a structure that’s familiar to the client. Each Web Service requires a stub for each client that executes it. You can reuse a stub for subsequent calls so you only need to create it once. However, simultaneous calls to a Web Service made by different threads will require that a unique client stub instance exists for each thread.

To create and compile a client stub for the loginUser Web Service:

  1. Locate the active WSDL file via HTTP for the Web Service you want to call. The URL is provided in with the documentation that describes each Web Service:

    It’s important that you access the runtime and not the static version of the WSDL document. Assuming that you included the modules holding the Web Services you want to access when you assembled your application, you should be able to download the runtime version of the WSDL.

  2. Use the Axis WSDL-to-Java tool to generate the client stub based on the WSDL.

  3. Compile the client stub.

Creating and Compiling a Client

A Web Service client is a Java file that describes precisely what the Web Service should do. It provides the actions the Web Service should commit and initial values.

If you want to enable Web Services to share sessions, your code needs to pass cookies between calls. The following example, which creates a static Web Service call to the loginUser Web Service, uses the CookieContainer class shown in Writing a CookieContainer Class:

{
 LoginUserSEIService loginService = new LoginUserSEIServiceLocator();
 LoginUserSEI loginStub = loginService.getLoginUserSEIPort();
 org.apache.axis.client.Stub axisStub = (org.apache.axis.client.Stub) loginStub;
 CookieContainer cookieContainer = new CookieContainer();

 axisStub.setMaintainSession(true);
 // Don't allow XML elements to reference other XML elements
 axisStub._setPropertyValue(AxisEngine.PROP_DOMULTIREFS, new Boolean(false));
 // Push cookies onto the Stub
 cookieContainer.pushCookies(stub);

 String userId = loginStub.loginUser("bhavern", " xyo8bnif", false);

 // Get cookies out of the Stub, and pass them to subsequent calls as needed
 cookieContainer.extractCookies(stub);
}
Creating a Call Using the Dynamic Invocation Interface (Dynamic)

A dynamic Web Service call holds all relevant information in one file, the client, which Axis converts directly into the SOAP message. Essentially, the client you create is a Java version of the call itself, excluding some relative values that are replaced with absolute ones at compile time.

Keep in mind that if you want to access a Web Service that uses non-standard data types, you need to create your Web Service call following the static process. See Creating a Call Using a Client Stub (Static).

If you want to enable Web Services to share sessions, your code needs to pass cookies between calls. The following example, which creates a dynamic Web Service call to the loginUser Web Service, uses the CookieContainer class shown in Writing a CookieContainer Class:

Service service = new Service();
Call call = (Call) service.createCall();

// Get a hold of a CookieContainer passed to this method/class
CookieContainer cookieContainer = new CookieContainer();

// Push previous cookies (if any) to the new Call object
cookieContainer.pushCookies(call);
call.setMaintainSession(true);

call.setTargetEndpointAddress(new
java.net.URL("http://hostname:port/userprofiling/usersession/loginUser/
loginUser") );

// Don't allow XML elements to reference other XML elements
call.setProperty(AxisEngine.PROP_DOMULTIREFS,Boolean.FALSE)

call.addParameter("Login",
 org.apache.axis.Constants.XSD_STRING,
 javax.xml.rpc.ParameterMode.IN);
call.addParameter("Password",
 org.apache.axis.Constants.XSD_STRING,
 javax.xml.rpc.ParameterMode.IN);
call.addParameter("IsPasswordEncrypted",
 org.apache.axis.Constants.XSD_BOOLEAN,
 javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
call.setOperationName(new QName("http://www.atg.com/webservices",
 "loginUser"));
String userId = (String) call.invoke( new Object[] { "bhavern",
 "xyo8bnif", Boolean.FALSE } );

// Extract new cookies from the Call into the CookieContainer object,
// which can then be passed to subsequent calls
cookieContainer.extractCookies(call);
}

Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices