Tuesday, April 22, 2014

Consuming SOAP Service without creating/using RequestVO/ResponseVO on Client Side

Many times in ADF/Webcenter implementation projects, consuming SOAP services is one of the requirement. Web Services are consumed in ADF by creating Web Service Data Control or by generating proxys.

Some of the services expect very few input parameters may be 2-4 but most of the Web Services expect more parameters. For services which expect more number of parameters, most of the times, all the input variables are a part of RequestVO POJO object. Since this RequestVO is required to provide input to the WebService, the structure with attributes of POJO or VO expected by the service needs to be shared to the client making the request.

For example, in this post we will be taking a simple example of EmployeeService.



This service has a signature of the exposed method as below :-

public EmployeeResponseVO getEmployeeDetails(EmployeeRequestVO employeeRequestVO)

All the required input paramters expected by getEmployeeDetail operation of the service are inside EmployeeRequestVO. And the parameters returned by the operation are in EmployeeResponseVO.

Now when client is consuming the service, either client should create a new request/respopnse vo(EmployeeRequestVO and EmployeeResponseVO in this case) or the WebService provider should share the request and response VO's to the client so that client can use the same.

Second option as mentioned above is not feasible, this is because the services provide is meant to provide and expose an operation using Web Services and is not responsible and does not have a contract to share request / response VO's along with its exposed WSDL. The first method of coding request/response VO;s can be done, but again it needs to be done for each and every operation which needs to be consumed by the client which will be time taking and also developer needs to do some research and needs to be sure about the number of attributes and their type in request/response VO's.

So in this Post we will be looking at how can we consume a SOAP Service without creating their request/response VO's.

Lets Get Started !!

We will be using two projects. WebServiceProducer and WebServiceConsumer. WebServiceProducer is a Generic Project having Web Services and Java as technology scope. This project has a simple EmployeeService having one operation getEmployeeDetails which accepts EmployeeRequestVO as input parameter and EmployeeResponseVO as output parameter.



The operation simply reads the input firstName, lastName and mobileNumber from EmployeeRequestVO and sets the response in EmployeeResponseVO with "Response from Service" appended in all three attribute.

EmployeeRequestVO and EmployeeResponseVO are simply POJO's both having attributes firstName,lastName and mobileNumber.


Deployed the web service on Integrated Weblogic service as and EAR and the service is available now.



On so we are good on services side. Now lets create a application to consume this same service.

We will create a Fusion Web Application in Jdev. Created with name WebServiceConsumer.

Now create a Webservice Data Control like below :




Enter name and WSDL URL




Do a simple next in next screens and click Finish.

Now you can see a data control named EmployeeServiceDC in data controls panel which has a method exposed by our web service.


Now lets quickly create a new page with three input fields, a managed bean in view scope having bindings to the three in put fields on the page - firstName, lastName and mobileNumber.





Action listener of the button is calling a method #{viewScope.EmployeeBean.callWebService} in EmployeeBean.

Now lets do the bindings.

Go to page bindings of testService.jspx and add a new AccessorIterator in executables section.

This will create Iterator with name arg0Iterator. Like below.


Now drag and drop the method in EmployeeServiceDB to the page.

A pop will come to Edit Action binding like below.



Now you will see that value of arg0 is already there. This value is for accessing current row. If it is not there , it needs be as below :

${bindings.arg0Iterator.currentRow.dataProvider}

Now check in the binding for this entry and remove the code manually for the button.


Now create attribute values bindings for all the input fields to be used in the page from data control. They are firstName , lastName and mobile number.


 Also add another AccssorIterator a returnIterator to access the response variables. 

At the end the bindings should look like below :



Ok so now we are done with the binding. We are left with one last thing and that is to code callWebService method in EmployeeBean. Below is this method.



DCIteratorBinding inputItorBinding =(DCIteratorBinding) dc.get("arg0Iterator");
Row row = inputItorBinding.getCurrentRow();

Above code gets the arg0Iterator and its current row and then adds the input parameters. This is the code for which we did all the things in the bindings. And also this is the place how we set the request parameters without creating a requestVO(EmployeeRequestVO) method. Same is with returnIterator in below code :

DCIteratorBinding returnItorBinding =(DCIteratorBinding) dc.get("ReturnIterator");
Row responseRow = returnItorBinding.getCurrentRow();

Now just run the page testService.jspx and enter the three fields. Click Submit (call web service from callWebService method in EmployeeBean)


Below is the output from the Service.




Hope this was useful !

Thanks



6 comments:

  1. can u please show demo of invoking adf mobile web service programmatically?
    can u please help me?

    ReplyDelete
  2. I liked your post. Is there any way to get the SOAP payload using this method?

    ReplyDelete
  3. Also can you please tell us is there any way to omit certail input parmeters.

    eg. I have a web service operations which required 4 input parameters. But sometimes I have to send only 1 parameter and service used to return response correctly in SOAP UI. But in ADF (above apporach) if I am not setting value to those attributes also remaining three tags are going with empty values. I assumed this because of I am getting SOAP error.

    How to fix this issue?

    ReplyDelete
  4. last month he share is herbal medicine in some medical hospital and now he is well recognize as one of the best in West Africa, you don’t have to be sad any more or share your tears any more on this virus when the cure have already be find in 2013 if you want to get in touch with him in private contact him on his email dr.chalaherbalhome@mail.com Or you can visit his website on https://
    drchalaherbalhome.godaddysites.com or https://mywa.link/dr.chalaherbalhome

    ReplyDelete