Monday, November 24, 2014

I start a six day break confused as to how to use the web services in Java.

Right-click on the applicable folder in NetBeans IDE 8.0.1 and pick "Web Service..." from the submenu under the "New" option in the menu which appears and you will be able to make a web service like so:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package foo.bar.baz.qux;
 
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
 
/**
 *
 * @author tjaeschke
 */
@WebService(serviceName = "AjaxWebService")
public class AjaxWebService {
 
   /**
    * This is a sample web service operation
    */
   @WebMethod(operationName = "hello")
   public String hello(@WebParam(name = "name") String txt) {
      return "Hello " + txt + " !";
   }
}

 
 

It's gonna look like this, and you'll have to click over to the "Source" tab to actually see the code:

 
 

Under your project in the "Projects" pane there will be a "Web Services" folder and therein you may right-click on your web service and pick "Test Web Service" to test the web service. It will bring up a form at a url such as http://localhost:8080/Java/AjaxWebService?Tester which will post to itself while passing, in the case of the example above, two fields PARAMhello0 and action with action passing "hello" for its value. { PARAMhello0: "World", action: "hello" } may be passed as an object to a jQuery .ajax POST against http://localhost:8080/Java/AjaxWebService?Tester to also get back the test results which are more than just what I'd expect for the usual results. The question is, how do I only get back the usual results. That I have yet to figure out.

No comments:

Post a Comment