IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Service Component Architecture programming > SCA programming model fundamentals > Developing service modules

Dynamically invoking a component

When an module invokes a component that has a Web Service Descriptor Language (WSDL) port type interface, the module must invoke the component dynamically using the invoke() method.

This task assumes that a calling component is invoking a component dynamically.

With a WSDL port type interface, a calling component must use the invoke() method to invoke the component. A calling module can also invoke a component that has a Java™ interface this way.


Procedure

  1. Determine the module that contains the component required.
  2. Determine the array required by the component.

    The input array can be one of three types:

    • Primitive uppercase Java types or arrays of this type
    • Ordinary Java classes or arrays of the classes
    • Service Data Objects (SDOs)

  3. Define an array to contain the response from the component.

    The response array can be of the same types as the input array.

  4. Use the invoke() method to invoke the required component and pass the array object to the component.

  5. Process the result.


Examples of dynamically invoking a component

In the following example, a module uses the invoke() method to call a component that uses primitive uppercase Java data types.

Service service = (Service)serviceManager.locateService("multiParamInf");
		
		Reference reference = service.getReference();

		OperationType methodMultiType = 
				reference.getOperationType("methodWithMultiParameter");

		Type t = methodMultiType.getInputType();

		BOFactory boFactory = (BOFactory)serviceManager.locateService
				("com/ibm/websphere/bo/BOFactory");

		DataObject paramObject = boFactory.createbyType(t);

		paramObject.set(0,"input1")
		paramObject.set(1,"input2")
		paramObject.set(2,"input3")

		service.invoke("methodMultiParamater",paramObject);

The following example uses the invoke method with a WSDL port type interface as the target.

Service serviceOne = (Service)serviceManager.locateService("multiParamInfWSDL");
	
	DataObject dob = factory.create("http://MultiCallWSServerOne/bos", "SameBO");
			dob.setString("attribute1", stringArg);

	DataObject wrapBo = factory.createByElement
		("http://MultiCallWSServerOne/wsdl/ServerOneInf", "methodOne");
			wrapBo.set("input1", dob); //wrapBo encapsulates all the parameters of methodOne
			wrapBo.set("input2", "XXXX");
			wrapBo.set("input3", "yyyy");

	DataObject resBo= (DataObject)serviceOne.invoke("methodOne", wrapBo);

Developing service modules