Where to include @Webresult ,@WebMethod etc

Friendy picture Friendy · Sep 11, 2015 · Viewed 13.1k times · Source

I have created a JaX Webservice through RAD(eclipse), and I am able to use the @WebParam annotation with my function parameter, however I also want to use @webresult etc but Don't know where should i specify them, on google I got interfaces but here i only have class and delegate class.

my class is

       public class GetFPDDataClass {

         public String GetFPDDataInput(String PolicyNumber)
         {

            return PolicyNumber;
         }

        }

and this is my delegate class

   @WebService (targetNamespace="fpd",   serviceName="GetFPDDataClassService", portName="GetFPDDataClassPort")
 public class GetFPDDataClassDelegate{

   fpd.GetFPDDataClass _getFPDDataClass = null;
     public String GetFPDDataInput (@WebParam(name="PolicyNumber") String PolicyNumber) {
      return _getFPDDataClass.GetFPDDataInput(PolicyNumber);
   }

    public GetFPDDataClassDelegate() {
        _getFPDDataClass = new fpd.GetFPDDataClass(); }

      }

Answer

Gas picture Gas · Sep 15, 2015

Both @WebResult and @WebMethod are set on the method level.

@WebResult is used to customize name of the XML element that represents the return value.

@WebMethod is used to mark business methods that are exposed to web service clients. By default all public methods in your class are exposed, if you don't implement web service interface.

Example:

 @WebMethod
 @WebResult(name="hellomessage")
 public String getHello() {
     ....
}

UPDATE:

If I dont have @WebResult I see the following xml:

<ns2:getHelloResponse>
    <return>hello fff</return>
</ns2:getHelloResponse>

with @WebResult:

<ns2:getHelloResponse>
   <hellomessage>hello fff</hellomessage>
 </ns2:getHelloResponse>