I am studying ‘Web Service’ this week and found good tutorial and example code.
on the page of 3, you can see CheckCard.java file which provide Web Service on server side.
This file contains a few methods such as
public static boolean validCC(String number)
public static boolean validCCNumber(String n)
public static int getCardID(String number)
public static boolean isNumber(String n)
public static String getCardName(int id)
public String doCheck(String aCard)
and 'doCheck()' method is the one I can invoke from client-side. What I want to ask you is why other methods are all static? Is this a rule or should it be static?
Web Service is very complicated for beginner and I just wonder every little things..
Could anybody give me a clue?
thanks
A WebMethod ,in this case
doCheck(String Card)is intended for remote method invocation and cannot be static. Doing so goes against the Web services model of relying on a proxy class, which, by its nature, needs to be instantiated as a genuine object to call the Web service.That is why other methods are all static and cannot be exposed as a service.