views:

28

answers:

1

Hi. I am developing a java client for a web service.

I have this method in my web service:

@WebMethod(operationName = "test")
public Integer test(@WebParam(name = "number")
int number) {
return number;
}

My client looks like this

public static void main(String[] args) { 
try { 

String BODY_NAMESPACE_VALUE = /namespace url/;
QName port = new QName(/Service name/);
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new QName(/Service name/));

Call call = service.createCall(port);
call.setTargetEndpointAddress(/WSDL location/);

call.setReturnType(XMLType.XSD_INT);

call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "test"));

call.addParameter("number", XMLType.XSD_INT, ParameterMode.IN);

Integer[] i = new Integer[1];
i[0] = new Integer(20);
System.out.println("test :"+call.invoke(i));


} catch (Exception ex) { 
ex.printStackTrace(); 
} 
}

I get return values ok from the web service in my java client since I tried getting a constant from the web service. However, in the case above I am trying to send 20 from the client to the web service and receive it back. However I am receiving 0. Does anyone know why sending parameters from client to web service is not working?

Thanks and regards, Krt_Malta

+1  A: 

I don't know if this is the answer but it appears as though you are sending the webservice an array of Integers

Integer[] i;

when it is only expecting a single int.

Strawberry
It's not that. Invoke takes only arrays of objects. I tried changing the web service to @WebMethod(operationName = "test") public Integer test(@WebParam(name = "number1") Integer[] number1) { return number1[0]; }but I still get a 0 result. Any ideas?
Krt_Malta
Try hard coding a return type in your service - to work out if its the argument coming in or being returned that is the problem.
Strawberry
The problem is in the coming in. In the web service I included System.out.println(i). On the server log the value is 0.
Krt_Malta
Ah now I understood what you meant. Yes hard-coding a return value in the service gives the correct value in the client.
Krt_Malta
Hi, I completely abondoned the method above. I used Sun's ws-import instead and it worked with no problems. Regards, Krt_Malta
Krt_Malta