This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes org.apache.axis.client.Call invoke method always returning string type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "org.apache.axis.client.Call invoke method always returning string type" Watch "org.apache.axis.client.Call invoke method always returning string type" New topic
Author

org.apache.axis.client.Call invoke method always returning string type

Shihad Salam
Greenhorn

Joined: Dec 15, 2010
Posts: 10
Hi,
I am new to Web Services.
When i am invoking a method(this method returns a Big Decimal value) in WebService, am getting the result as String type always in client. But I need Big Decimal value in Client class.
Service service = new Service ();
Call call = (Call) service.createCall ();
call.setTargetEndpointAddress (new URL (endpoint));
call.setOperationName ("farenheitToCelsius");
<b>Object celToFar = call.invoke (new Object[] {BigDecimal.valueOf (64)});</b>
The method "farenheitToCelsius" always returns Big Decimal value. But in Client class 'celToFar' is getting as String instead of BigDecimal.
Please Help.
Full Code given below:


WebService Class
<code>
@WebService
public class TestWS
{
@WebMethod
public BigDecimal celsiusToFarenheit (BigDecimal temp)
{
BigDecimal result = temp.multiply (BigDecimal.valueOf (1.8)).add (BigDecimal.valueOf (32));
return result;
}

@WebMethod
public BigDecimal farenheitToCelsius (BigDecimal temp)
{
BigDecimal result = temp.subtract (BigDecimal.valueOf (32)).divide (BigDecimal.valueOf (1.8), 2,
RoundingMode.HALF_UP);
return result;
}

}
</code>
-----------------------------------------------------------------

Client Class
<code>
public class TestClient
{
public static void main (String[] args)
{
try
{

String endpoint = "http://localhost:8081/WebServices/services/TestWS";
Service service = new Service ();
Call call = (Call) service.createCall ();
call.setTargetEndpointAddress (new URL (endpoint));
call.setOperationName ("farenheitToCelsius");
<b>Object celToFar = call.invoke (new Object[] {BigDecimal.valueOf (64)});</b>
System.out.println ("celToFar::" + celToFar);
}
catch (Exception e)
{
System.err.println (e.toString ());
}
}
}
</code>
----------------------------------------------------------------------

TestWS.wsdl
<code>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://test.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://test.com" xmlns:intf="http://test.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://test.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="celsiusToFarenheit">
<complexType>
<sequence>
<element name="temp" type="xsd:decimal"/>
</sequence>
</complexType>
</element>
<element name="celsiusToFarenheitResponse">
<complexType>
<sequence>
<element name="celsiusToFarenheitReturn" type="xsd:decimal"/>
</sequence>
</complexType>
</element>
<element name="farenheitToCelsius">
<complexType>
<sequence>
<element name="temp" type="xsd:decimal"/>
</sequence>
</complexType>
</element>
<element name="farenheitToCelsiusResponse">
<complexType>
<sequence>
<element name="farenheitToCelsiusReturn" type="xsd:decimal"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>

<wsdl:message name="farenheitToCelsiusResponse">

<wsdl:part element="impl:farenheitToCelsiusResponse" name="parameters">

</wsdl:part>

</wsdl:message>

<wsdl:message name="farenheitToCelsiusRequest">

<wsdl:part element="impl:farenheitToCelsius" name="parameters">

</wsdl:part>

</wsdl:message>

<wsdl:message name="celsiusToFarenheitRequest">

<wsdl:part element="impl:celsiusToFarenheit" name="parameters">

</wsdl:part>

</wsdl:message>

<wsdl:message name="celsiusToFarenheitResponse">

<wsdl:part element="impl:celsiusToFarenheitResponse" name="parameters">

</wsdl:part>

</wsdl:message>

<wsdl:portType name="TestWS">

<wsdlperation name="celsiusToFarenheit">

<wsdl:input message="impl:celsiusToFarenheitRequest" name="celsiusToFarenheitRequest">

</wsdl:input>

<wsdlutput message="impl:celsiusToFarenheitResponse" name="celsiusToFarenheitResponse">

</wsdlutput>

</wsdlperation>

<wsdlperation name="farenheitToCelsius">

<wsdl:input message="impl:farenheitToCelsiusRequest" name="farenheitToCelsiusRequest">

</wsdl:input>

<wsdlutput message="impl:farenheitToCelsiusResponse" name="farenheitToCelsiusResponse">

</wsdlutput>

</wsdlperation>

</wsdl:portType>

<wsdl:binding name="TestWSSoapBinding" type="impl:TestWS">

<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdlperation name="celsiusToFarenheit">

<wsdlsoapperation soapAction=""/>

<wsdl:input name="celsiusToFarenheitRequest">

<wsdlsoap:body use="literal"/>

</wsdl:input>

<wsdlutput name="celsiusToFarenheitResponse">

<wsdlsoap:body use="literal"/>

</wsdlutput>

</wsdlperation>

<wsdlperation name="farenheitToCelsius">

<wsdlsoapperation soapAction=""/>

<wsdl:input name="farenheitToCelsiusRequest">

<wsdlsoap:body use="literal"/>

</wsdl:input>

<wsdlutput name="farenheitToCelsiusResponse">

<wsdlsoap:body use="literal"/>

</wsdlutput>

</wsdlperation>

</wsdl:binding>

<wsdl:service name="TestWSService">

<wsdl:port binding="impl:TestWSSoapBinding" name="TestWS">

<wsdlsoap:address location="http://localhost:8081/WebServices/services/TestWS"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

</code>
 
Don't get me started about those stupid light bulbs.
 
subject: org.apache.axis.client.Call invoke method always returning string type
 
Similar Threads
How do I consume Web Services in Swing
Webservice throwing Nullpointer exception
InstantiationException, axis error
creating a SOAP request from WSDL
Problem with mapping Array String into HashMap in Axis