Friday, February 17, 2017

Steps to create web service Producer(Using annatation and bean config) and Consuming webservice

Steps to create web service (Producer)

First down load the required jar files

a. Go to http://xfire.codehaus.org/Download
b. down load xfire-distribution-1.2.6.zip file
c. extract this and go to lib folder
d. And copy all jars to your application.


1.add xfire.xml file



2.configure org.codehaus.xfire.spring.remoting.XFireExporter








3.configure handler mapping





citationService.xfire




4.write proxy interface

TestInterface:
package com.optrasystems.mvc;
public interface TestInterface {
public String sayHello();
}

5.write a class with exposed methods

Test.java;

package com.optrasystems.mvc;
public class Test implements TestInterface{
public String sayHello(){

String string="old String";
return string;
}
}



Consuming above webservice
==========================
first generate the java file using wsdl file

select project right click ---> new -->other-->select "web service client" (in webservice) --->click on 'next' button -->provide wsdl path in 'service defination' input box and decrease valume type bar to 'Develop client'---> click on finish

1. using Xfire:

XFireClientFactoryBean client=new XFireClientFactoryBean();
try{
client.setServiceClass(Class.forName("com.optrasystems.mvc.TestInterface"));
client.setWsdlDocumentUrl("http://192.168.100.151:8089/thorlabs/app/citationService?WSDL");
client.afterPropertiesSet();
client.getObject();
TestInterface lTestInterface=(TestInterface)(client.getObject()));
String str=lTestInterface.sayHello();
request.getSession().setAttribute("webservice", str);
}catch(java.lang.Exception e){
e.printStackTrace();
}


==================================================
Creating web service using Spring Annatation

step 1: create proxy interface

@WebService
public interface PilotSystemWebservice {
//declare all exposed methods here.
}

step 2: create implementation class for the above interface

@WebService(serviceName="shekhar",endpointInterface="com.optrasystems.service.PilotSystemWebservice")
public class PilotSystemWebserviceImpl implements PilotSystemWebservice {
// implement all method.
}

step 3: add the following bean configuration to Spring context.








step4: WSDL file Url is
http://localhost:8089/thorlabs/app/services/shekhar?wsdl

thorlads : application name
app : url-pattern of DispatcherServlet configured in web.xml
services: constant url for all ,this sanded url provided by Spring
shekhar :service name provided in Interface( serviceName="shekhar")


step 5: client will be same(above one) for this application

No comments: