Topic
No replies
anu20
anu20
1 Post
ACCEPTED ANSWER

Pinned topic Java client consuming SOAP web service usind Dynamic inteface Invocation

‏2012-03-02T07:05:31Z |
Hi ,

I am trying to consume web service via java client. But it returns missing float value.
Some one pls help me!!!!!!

Java Client accessing "http://soaptest.parasoft.com/calculator.wsdl

Steps Follwed:
1) Eclipse -> create java project
2) Add libs axis-1.2.1, axis-jaxrpc etc
3) create java client

RESPONSE: AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
faultSubcode:
faultString: java.io.IOException: java.lang.NumberFormatException: missing float value
faultActor:
faultNode:
faultDetail:

Java Client

import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.encoding.XMLType;
public class test {
public static void main(String args[]) {
try {
// Create a service class with no WSDL information. You
// still must know something about the WSDL, however: the
// service's name.
QName serviceName = new QName(
"http://soaptest.parasoft.com/calculator.wsdl ",
"Calculator");
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(serviceName);
// Now create a dynamic Call object from this service.
// This call object is not yet associated with any
// operation. We'll do that below.
Call call = service.createCall();
// Next, build up the information about the operation...
// The operation name
QName operationName = new QName("add");
call.setOperationName(operationName);
// The input parameter
call.addParameter(
"x", // parameter name
XMLType.XSD_FLOAT, // parameter XML type QName
ParameterMode.IN); // parameter mode
call.addParameter(
"y", // parameter name
XMLType.XSD_FLOAT, // parameter XML type QName
ParameterMode.IN); // parameter mode
// The return
call.setReturnType(XMLType.XSD_FLOAT);
// The operation is an RPC-style operation.
// call.setProperty( Call.OPERATION_STYLE_PROPERTY, "document");
// The encoding style property value comes from the
// binding's operation's input clauses encodingStyle
// attribute. Note that, in this case, this call is not
// really necessary - the value we're setting this
// property to is the default.
call.setProperty(
Call.ENCODINGSTYLE_URI_PROPERTY,
"http://schemas.xmlsoap.org/soap/encoding/");
// The target endpoint
call.setTargetEndpointAddress(
"http://ws1.parasoft.com/glue/calculator");
// Invoke the operation
Float[] actualArgs = {(float)8, (float)9};
System.out.println(actualArgs[0]);
System.out.println(actualArgs[1]);
// Float price = (Float) call.invoke(actualArgs);

// float x=7.8f, y=7.9f;
Float responseObj = (Float)call.invoke(actualArgs);
// System.out.println("price = " + responseObj.);
}
catch (Throwable t) {
t.printStackTrace();
}
}
}