tag:blogger.com,1999:blog-67261498921656730922024-03-13T12:23:24.512-07:00Java WebservicesKarunahttp://www.blogger.com/profile/02921666284983115261noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-6726149892165673092.post-37347075797038877242012-04-13T14:10:00.171-07:002012-04-16T11:33:49.776-07:00Creating Bottom Up WebServices<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white; text-align: -webkit-auto;">Web services can be created using two methods: top-down development and bottom-up development. Bottom-up Web services development involves creating a Web service from a Java bean or enterprise bean.</span> </span></div><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white; text-align: -webkit-auto;">When creating a Web service using a bottom-up approach, first you create a Java class and then use the Web services wizard to create the WSDL file and Web service.</span> </span></div><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white;">Prerequisites: </span><span style="background-color: white;">Install Apache Tomcat6.0.2,</span><span style="background-color: white;">Eclipse IDE,</span><span style="background-color: white;">Apache Axis-2 1.4.1</span></span></div></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;">Create a new Dynamic Web Project in Eclipse</span></div></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white;">New-->DynamicWebProject </span><span style="background-color: white;">Give the project name as TestServices.</span></span></div></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white;">Select the </span><span style="background-color: white;">Target</span><span style="background-color: white;"> runtime Apache Tomcat </span><span style="background-color: white;">In the configuration </span><span style="background-color: white;">click on</span><span style="background-color: white;"> modify then select Axis2 webservices as shown below.</span></span></div></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="background-color: white;">Note: To install Axis2 in Eclipse go to windows-->Preferences-->WebServices--></span><span style="text-align: left;"> Axis2 Preferences </span><span style="text-align: left;">Under the tab Axis2 runtime browse for axis2 runtime location and click ok.</span></span></div><div style="text-align: justify;"><b style="text-align: left;"><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span></b></div><div style="text-align: justify;"><b style="text-align: left;"><span style="font-family: Times, 'Times New Roman', serif;">Step:1 </span></b></div><div style="text-align: justify;"><b style="text-align: left;"><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span></b></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT1phyNTDu4K9g2cX-BRd_i99Wxh8Cy7gQfwe3QwTHdSvNKBQk90ieuv1bwZEF_WYC3pEalU5jI9yNcMzSbXPuJRHYjdjUIvtgo_8fDxEYFDjrK6BzcSp-nl6yUuOQBiqdBXtkidpXPm16/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT1phyNTDu4K9g2cX-BRd_i99Wxh8Cy7gQfwe3QwTHdSvNKBQk90ieuv1bwZEF_WYC3pEalU5jI9yNcMzSbXPuJRHYjdjUIvtgo_8fDxEYFDjrK6BzcSp-nl6yUuOQBiqdBXtkidpXPm16/s640/2.png" width="640" /></span></a></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif; text-align: left;"><br />
</span></div></div><div class="separator" style="clear: both; text-align: center;"></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><b>Step: 2 </b> U</span><span style="font-family: Times, 'Times New Roman', serif;">nder src create a java class as shown below</span></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZPHMQg9EkvBEeWu9cLaQmyq8wGGV_6HqLVt9YzSJEx3Jh7PBvGlgIaGVh1f3YeAYv_bWoLeomZg93Mwi-_ntQJLUDYxaTcmJ75-D8vfXxKFP7fJ9XwaQCQzFh5V-fUGvg7iaalW1BGoDH/s1600/2-png.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZPHMQg9EkvBEeWu9cLaQmyq8wGGV_6HqLVt9YzSJEx3Jh7PBvGlgIaGVh1f3YeAYv_bWoLeomZg93Mwi-_ntQJLUDYxaTcmJ75-D8vfXxKFP7fJ9XwaQCQzFh5V-fUGvg7iaalW1BGoDH/s640/2-png.jpg" width="640" /></span></a></div><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><b><br />
</b></span></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><b style="font-family: Times, 'Times New Roman', serif; text-align: justify;">Step:3 </b><span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: justify;">Under WebContent-->WEB-INF-->services </span><br />
<div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;">create two folder called HelloService-->META-INF and paste the service.xml file here as shown below.In the service.xml file you need to specify the Servicename and service class.</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWlR8_A_InF4ovMy3N8UtnqBqCW4pOiBCXHAlqRJsM6KtTTeAAhD6SJz00UHPGB4Bh8rasJqPKQizLLUEpPpV-YHd_IDRjuGcBybsjJnxsuh5AO7Loambg8Fxztwo4uJHo1lM6nwjsYVza/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;"><span style="font-family: Times, 'Times New Roman', serif;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWlR8_A_InF4ovMy3N8UtnqBqCW4pOiBCXHAlqRJsM6KtTTeAAhD6SJz00UHPGB4Bh8rasJqPKQizLLUEpPpV-YHd_IDRjuGcBybsjJnxsuh5AO7Loambg8Fxztwo4uJHo1lM6nwjsYVza/s640/3.png" width="640" /></span></a></div><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><b><br />
</b></span></div><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><b><br />
</b></span></div></div><div style="text-align: -webkit-auto;"><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif;"><br />
</span></div></div><div style="text-align: justify;"><span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<b style="font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;">Step:4 </b><span style="font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;">When you run the project the Deployment descriptor will invoke the services.xml file automatically. Since we are specifying our java class in the services.xml file it will invoke service.xml file and generate the WSDL file on the fly.</span><br />
<div style="text-align: -webkit-auto;"><span style="font-family: Times, 'Times New Roman', serif;">Select the project (TestServices) and right click on it Run As-->Run on server</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdo2VdlGfVkStOuqx4ozf2IwZ2g3cJ_eNuROe_IUdXv-kmrQ99R2eab3-ry3eXPzZuzNqS3tlmbP7GAnvYZBo-WzU3zQ9wZboFqVJC07kYEy4JmiPLGihe_NJeEXlm7Zb_uJgVt3911k7n/s1600/4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Times, 'Times New Roman', serif;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdo2VdlGfVkStOuqx4ozf2IwZ2g3cJ_eNuROe_IUdXv-kmrQ99R2eab3-ry3eXPzZuzNqS3tlmbP7GAnvYZBo-WzU3zQ9wZboFqVJC07kYEy4JmiPLGihe_NJeEXlm7Zb_uJgVt3911k7n/s640/4.png" width="640" /></span></a></div><div style="text-align: -webkit-auto;"><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span></div><div style="text-align: -webkit-auto;"><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span></div><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span style="font-family: Times, 'Times New Roman', serif;"><b>Step :5</b> </span><span style="font-family: Times, 'Times New Roman', serif;">When you click on Services in the browser you can see the list of services and methods defined for the service .In our case we have only one service called HelloService as show below..</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRa5MFp-upcMY_L4GrbRnTMjleizzts-rQaOWrUg0T279x6uIWXfoPFaA_baDpyjB8fCg0NW03ePjIlXaa8p5B5KDHvcQw6AQGXWL0Nk2UUUm0-N7NNcWgAikqoflY4znX-QPyAuTkUb3/s1600/5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="font-family: Times, 'Times New Roman', serif;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRa5MFp-upcMY_L4GrbRnTMjleizzts-rQaOWrUg0T279x6uIWXfoPFaA_baDpyjB8fCg0NW03ePjIlXaa8p5B5KDHvcQw6AQGXWL0Nk2UUUm0-N7NNcWgAikqoflY4znX-QPyAuTkUb3/s640/5.png" width="640" /></span></a></div><div><span style="font-family: Times, 'Times New Roman', serif;"><br />
</span></div><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><b>Step : 6</b> </span><span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;">When you click on the HelloService you can see the WSDL file. Axis engine will generate wsdl file on the fly for us.</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4YuVKuz_my7S41doXs6e0bcXbnUwZj_iTRq0JpqMqCJoODDMm6oW3FayksVL7tVpG09VgIe99-ERbQKsi1YtOTz_RzU_SXT-k_oJ9tZlnxnDenkEZ1j7LqOsdymJ59VvsdfyGyXiENm1_/s1600/6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4YuVKuz_my7S41doXs6e0bcXbnUwZj_iTRq0JpqMqCJoODDMm6oW3FayksVL7tVpG09VgIe99-ERbQKsi1YtOTz_RzU_SXT-k_oJ9tZlnxnDenkEZ1j7LqOsdymJ59VvsdfyGyXiENm1_/s640/6.png" width="640" /></a></div><span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"></span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Times, 'Times New Roman', serif; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br />
</span><br />
<span style="background-color: white; font-family: Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br />
</span><br />
<span style="font-family: Arial, sans-serif; font-size: x-small; text-align: -webkit-auto;">This is how you create a topdown webservices. Now lets go through consuming the webservices.</span><br />
<span style="background-color: white; font-family: Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br />
</span></div></div>Karunahttp://www.blogger.com/profile/02921666284983115261noreply@blogger.com7