Skip to Content

In a project scenario one may have to call a web service created in .net(DOTNET), with ANY tag in its WSDL file, in a Web Dynpro Java application. This is not at all possible in CE 7.1 and lower versions of NWDS as the Adaptive web service model does not support it. In CE 7.11 and higher versions of NWDS, Adaptive web service model supports ANY tag by means of org.w3c.dom.Element, but does not support the attributes and their values for the xml tags.

Below is the xml tag structure which is supported in Adaptive web service model (CE 7.11 and higher versions).

<Batch>
     <Method>
          <Field>8</Field>
     </Method>
</Batch>

Below is the tag structure which is not supported in Adaptive web service model (CE 7.11 and higher versions).

<Batch ListVersion="0" OnError="Continue" PreCalc="TRUE">
     <Method Cmd="Delete" ID="1">
          <Field Name="ID">8</Field>
     </Method>
</Batch>

In such cases, where the need is to consume a web service with ANY tag and pass a complex xml tag structure with attributes and values defined, then the alternate approach would be to consume this web service in EJB and then use this EJB in web dynpro Java application by means of Enterprise JavaBean Model. Below are the steps to consume a WSDL/Web Service in EJB. For more info on creating and integrating EJB with Web Dynpro java refer this link Integration of EJB with Web Dynpro Java

  • After the EJB has been created and is wrapped with an EAR DC (i.e. DC of type Enterprise Portal), import the wsdl file into the EJB, i.e. in the context menu of the EJB DC, choose Import –> Import… –> Expand Web services and choose WSDL –> Choose Next. In the WSDL Import Wizard choose Remote Location/File System and click on Next –> Enter the URL of the Web service and choose Finish. Below screen shot shows the EJB DC structure after the WSDL file is imported into it.Right click on the WSDL file and in the context menu choose

wsdlImport.jpg

Web Services   –> Choose Generate Java bean skeleton. In the Web service wizard choose next –> in the next window choose Specify JAX-WS customization files and choose Next –> in the next window choose Finish. The EAR DC will be deployed.

  • Now we have to create the proxy client for the web service. Expand your EJB DC. In the context menu of the imported WSDL file choose Web Services –> Choose Generate Client and follow the same steps as explained above, choosing Specify JAX-WS customization files. This will generate the proxy class that will be used to execute the web service.
  • Now we can write the business logic in the Bean class to execute the web service.

Code snippet to instantiate the proxy class of the web service and execute the web service is as below,

URL wsdlLocation = new URL("<WSDL URL>");
//Here name is the Proxy class name and the targetNamespace is the namespace defined for the proxy in the proxy class’s “.java” file.
<ProxyClassName> proxyClass = new <ProxyClassName>(wsdlLocation, new QName(<targetNamespace>,<name>));
//Here the interface is the .java file created along with proxy class, which holds declaration of all the methods (requests) in it.
<ProxyInterfaceName> proxyInt = proxyClass.getConfig1Port_Document ();

Now “proxyInt” can be used to call the methods (request) to execute the web service. For Example proxyInt.getContent(“FileName”, “RID”, “MimeType”);

Also if user authentication is required to execute the web service, then the below snippet can be used to set the user name and password to execute the web service. This snippet has to be placed before calling the request method.

((BindingProvider) proxyInt).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "UserName");
((BindingProvider) proxyInt).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "Password");

In the Java skeleton generated for the WSDL file, “ANY” tag will be represented as a list of Object i.e. List<Object>. To add a complex xml tag (as defined earlier), to the list, create the xml tag structure by means of APIs defined under org.w3c.dom and add it to the list.

Below is the snippet to create the complex xml tag with attributes and values as defined above. In the below snippet “batchElement” is the root xml tag and this has to be added to the list. 

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.newDocument();

Element batchElement = dom.createElement("Batch");
batchElement.setAttribute("OnError" , "Continue");
batchElement.setAttribute("PreCalc","TRUE");
batchElement.setAttribute("ListVersion","0");
batchElement.setAttribute("ViewName", "");

Element methodElement = dom.createElement("Method");
methodElement.setAttribute("ID", "1");
methodElement.setAttribute("Cmd", "Delete");

Element fieldElement = dom.createElement("Field");
fieldElement.setAttribute("Name", "ID");
fieldElement.appendChild(dom.createTextNode(itemId));

methodElement.appendChild(fieldElement);
batchElement.appendChild(methodElement);
dom.appendChild(batchElement);

This way, we can consume the web services with ANY tag in EJB and then in turn, in the WebDynpro Java applications.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply