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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |