Hi Massimo,

Axis is responsible for the creation of MyClass objects. So Axis creates an
instance of the service implementation using the newInstance() method of
class Class. Axis expects a default constructor. Normally the Java compiler
generates a default constructor, but if you write your own constructor the
Java compiler doesn't insert a default constructor.
So you can use two constructors one default for Axis and one if you use the
class somewhere else. But if you want Axis to initialize your service you
can use the init() method of the ServiceLifecycle interface and parameters
from the wsdd file.

Thomas


WSDD:

<service name="MyService" provider="java:RPC">
  <parameter name="className" value="MyClass"/>
  <parameter name="a" value="1"/>
  <parameter name="b" value="2"/>
</service>



MyClass:

public class MyClass implements ServiceLifecycle {
    private int a=0;
    private int b=0;

    public void init(Object servletEndpointContext) throws ServiceException
{

      MessageContext msgContext = MessageContext.getCurrentContext();

      System.out.println("a: " + msgContext.getProperty("a"));
      System.out.println("b: " + msgContext.getProperty("b"));
    }

    public void destroy() {
    }

    public int callMe{
        return a+b;
    }

}

> -----Urspr�ngliche Nachricht-----
> Von: Massimo Barabino [mailto:[EMAIL PROTECTED]
> Gesendet: Montag, 1. September 2003 13:02
> An: [EMAIL PROTECTED]
> Betreff: Re: Passing parameters to constructor
>
>
> vairamuthu thayapavan wrote:
>
> >hi
> >i think u mean the ws classes in axis. for that 1st specify a default
> >constructor with out any parameter. then specify ur constructor with
> >required parameter.
> >-
> >thayapavan
> >
> >
> Hi,
> Thanks a lot for the replies.
> Maybe I need to be more specific with what I mean as "the constructor of
> the java class invoked by axis". Suppose my Service just consists of one
> simple class as follows.
>
> public class MyClass{
>     private int a=0;
>     private int b=0;
>
>     public MyClass(){
>         this.a=1;
>         this.b=2;
>     }
>
>     public int callMe{
>         return a+b;
>     }
>
> }
>
> If the constructor remains as I wrote, everithing goes OK. As I change
> it as follows I get fault codes
>
> ...
>
> public MyClass(int a, int b){
>         this.a=a;
>         this.b=b;
>     }
> ...
>
> This is my problem. (may be Thomas' and your replies already apply to
> this...)
>
> Thanks once again
>
> Massimo Barabino
>
>
BEGIN:VCARD
VERSION:2.1
N:Bayer;Thomas;;Herr
FN:Thomas Bayer
TITLE:Gesch�ftsf�hrer
TEL;WORK;VOICE:(0621) 71839-35
ADR;WORK:;;Weinheimer Str. 68;Mannheim;BW;68309;Deutschland
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Weinheimer Str. 68=0D=0AMannheim, BW 68309=0D=0ADeutschland
URL:
URL:http://www.oio.de
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20010810T095047Z
END:VCARD

Reply via email to