publishing a method as webservice
I have some functions which i want to publish as a webservice .Am preferring axis 2 web service.The return type of my methods is some bean that i developed.
1)How can i return it using webs开发者_JAVA百科rice? 2)will the client understand the bean?Eg
Mycustom object getObjbyId(int id){
//get the object from db and process it
//return myobj
}
If now how can i go about it?Should i write code to convert the object into xml?Or is there any way by which i can do it automatically?
Axis supports JAX-WS, and using JAX-WS you can have something like:
@WebService
public class MyService {
@WebMethod
MyObject getObjbyId(@WebParam int id) {
//get the object from db and process it
//return myobj
}
}
Then you can publish that using the Endpoint
class:
Endpoint.publish("http://localhost:8080/WS/MyService", new MyService());
For more information see this and this.
If you are using Eclipse, then it has the option to create the web service from the java class. Just select the java class. right click and select Web Service menu. Download the necessary plugins if this option is not visible
精彩评论