Skip to Content
This Document deals with How to Create a Simple Java Web Service and How to consume that service in Web Dynpro and When Web Service is got changed, how to re-import into web dynpro with out deleting the model. Prerequisites   1)Minimum Java Programming is required.    2)Should know how to use NWDS.    3)Basic Idea about web Services.    4)Good knowledge on Web Dynpro. Note:     For Simplicity took Java Web Service, instead we can use EJB Web service also.  Creating Web Service is very simple. In the below example I took web service with 2 methods.  Web Service CreationStep: -1  NWDS -> Java Perspective -> Create a Java Project and a class. Ex: – public class SampleServiceClass {      public String sayHello(String name){           return “Hello..”+name;      }      public double result(int a1,float a2,int a3){           return a1+a2+a3;      } } Step -2: Go to Web Services perspective  Right Click on Class -> New -> Web Service -> Give Web Service Name (SampleService) -> Finish. Then Virtual Interfaces, Web Services Definitions, Web Service Configurations will be created in the project. Step -3: Right Click on the project -> Build EAR. Step -4: Right Click on the ear file -> Deploy. Service (SampleService) is ready; check it from Web Service navigator.  Creating Web Service Model in Web Dynpro Web Dynpro -> Project -> WebDynpro Explorer Models ->Right Click -> Create Model  Model Name: TestService Path: com.sdnblog.comp.model WSDL Source: Local File System or URL imageFig a:- Creating Web Service Model  When Web Service Model is created in Web Dynpro then, the corresponding classes and files will be created. You can find them from navigator perspective.  Project -> bin (Temporary one. Automatically created) gen_wdppackagescomsdnblogcompmodel srcpackageswsdls srcpackagescomsdnblogcompmodel (See in Fig – B) imageFig B :- Web Service Model Classes and Files Web Service Change If web service got changed, like adding new method to the web service (or) changing the method syntax(Parameter Type Change) (or) adding any extra parameter to the existing service, then that service need to be re-imported into Web Dynpro, otherwise it won’t work. For Example for the above method – result, if we add extra parameter (4th parameter) then method will be  Ex: – public double result (int a1, float a2, int a3, int a4) {      return a1+a2+a3+a4; } ErrorIf we don’t re-import this new model in to our project, then it will throw error like this Service call exception; nested exception is: com.sap.engine.services.webservices.jaxrpc.exceptions.XmlUnmarshalException: XML Deserialization Error.  Re-importing Model For Re-importing model, I am not using any ready made solution, for that I am creating this new model in a sample project and copying that model generated classes and files into the original project. For this follow the below steps.  Step – 1 Web Dynpro -> Create a Sample Project -> Create Web Service model like above.  Project Name – TestProject Model Name: TestService Path: com.sdnblog.comp.model WSDL Source: Local File System or URL Note – We are copying the newly created model to original project model, so names and path should be same like original project. Otherwise it won’t work. Here we replacing the old model classes with newly created model classes.  Step -2  Copy the new model files from TestProject to Original Project (WebServiceReimportPro). gen_wdppackagescomsdnblogcompmodel srcpackageswsdls srcpackagescomsdnblogcompmodel  Reload + Re-Build the Web Dynpro project.  Project will be loaded with new model changes, now we can see all changes like extra parameters.  Step – 3 If extra parameters are added to any method or method parameter type changed then(See Fig :- C), Go to the Component Controller / Custom Component Controller Context where that method is binded -> Right Click on the context method node -> Edit Model Binding -> Select the extra parameter -> Finish. imageFig C:- Re-Imported Method Structure  In the same way from View Context -> Right Click on the context (method) node -> Edit Model Binding -> Select the extra parameter -> Finish.  Step-4:  If Extra Method is added then, that method will be showed, use this method in normal way.  Step-5: Reload + Re-Build the Web Dynpro project.    Note: – Some times, project bin folder might have some errors, in that case just close the project and open it. Uses – – We practically observed that, this procedure takes less time to re-import web service. – Less Complexity – The same procedure can be applies to RFC – Web Services also. – No Need to delete the model. – Less Complexity.  Execute: – Web Services Authentication If Service require pass User name and PWD like this. wdContext.RootNodeElement().modelObject()._setUser(“usr”); wdContext.RootNodeElement().modelObject()._setPassword(“pwd”);  Note: –   If you are re-importing Web Service from DTR, then you may have to check-in all the files manually. Other Usefull Links1)Web Service Model in Web Dynpro https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/46bae990-0201-0010-bc98-d2fecedfaf32  2)For More information on Authentication please go thru the below link. https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/aed49d0d-0301-0010-6d84-e3e104dc1644  3)For information on Web Service Re-Import go through below link. How To Reimport Web Service Models in Web Dynpro for Java  4)About Web Services http://www.w3.org/TR/wsdl.
To report this post you need to login first.

6 Comments

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

  1. Sai Reddy
    Blog is informative and helpful.
    By this way, we can re-import web services if the method signature changes or any extra file is added.
    Is there any way if two models are merged into one model? Can we use this procedure?
    (0) 
    1. Sridhar k Post author
      Thank you.

      If you merge any other model into this, probably it treats all the extra added methods as new method coz, package structure changes.

      (0) 
  2. Anonymous
    Hi
    I want to import web service from ERP system to my web dynpro application. I have saved wsdl file and trying to create model using adaptive web service option. But my model object does not have _setUser() and _setPassword() function.

    Please let me know if you have any idea regarding this.

    (0) 
    1. Sridhar k Post author
      Hello,

      I Guess…it wont be any problem. If you try accessing that service methods is it asking for UID and PWD? If it is not, it’s not having any security constraint in acessing.

      (0) 

Leave a Reply