dcsimg

Apache SOAP 2.2 Overview Page 10

By ServerWatch Staff (Send Email)
Posted Mar 8, 2002


Construction and Sending of SOAP Messages

The construction of the SOAP message uses the methods in the Call class. This class defines the set of characteristics that make up an RPC. Among these methods, two phases are involved in the call.

The service identification phase, represented by:

  • setTargetURI(String identifiant_du_service)
  • setMethodName(String nom_des_methodes_du_service)
  • setEncodingStyleURI(String uri_encodage)

The construction and request sending phase:

  • setParams(Vector mes_parametres)
  • invoke(URL http://mon.web.service..., String soapActionField)

The method setParams is used to define the variables that will be sent to the server. This definition uses the Parameter class, which instantiates an object taking as its arguments name, type, value, and coding (empty by default).

The invoke method triggers the mechanism to send the SOAP request to the relevant service. This service is identified by a URL. The URL of our service will be the local server on which the Web service is deployed.

http://localhost:8080/soap/servlet/rpcrouter/

Thus, for our calculator example, we will have the following code:

 Long nbr1 = Long.valueOf(args[0]); Long nbr2 = Long.valueOf(args[2]); 
URL url = new URL("http://localhost:8080/soap/servlet/rpcrouter"); 
Call call = new Call(); //Name of service call.setTargetObjectURI("urn:Calculator"); 
if (args[1].equals("+")){ // Name of service method call.setMethodName("add");
 } ... // Coding call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); Vector params = new Vector(); 
// Declaration of parameters params.addElement(new Parameter("nbr1", Long.class, nbr1, null)); 
params.addElement(new Parameter("nbr2", Long.class, nbr2, null)); 
call.setParams(params); Response resp = null; try{ // SOAP request send resp = call.invoke(url, soapActionField); } ... //processes 



Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.