I want to connect to the web service with apache axis in java and I have some wrong parameter but I don't know which:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class Test_Web_Service
{
public static void main(String [] args) throws Exception {
try {
String endpoint = "http://www.w3schools.com/webservices/tempconvert.asmx";
Service service = new Service();
Call call= (Call) service.createCall();
call.setProperty( Call.SOAPACTION_USE_PROPERTY, new Boolean( true ) );
call.setProperty( Call.SOAPACTION_URI_PROPERTY, "http://tempuri.org/CelsiusToFahrenheit");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://tempuri.org/CelsiusToFahrenheit","CelsiusToFahrenheit"));
String ret = (String) call.invoke( new Object[] {"20"} );
System.out.println("Sent '20', got '" + ret + "'");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
web service link: http://www.w3schools.com/webservices/tempconvert.asmx
In ret variable I get message Error. Is this because I have wrong parameter in QName.
This is due to impedence mismatch beetween the client code and the service.server is not able to decode your request, and continue processing with default values
You can try this instead
call.setOperationName(new QName("http://tempuri.org/","CelsiusToFahrenheit"));
call.addParameter(new QName("http://tempuri.org/","Celsius"),XMLType.XSD_STRING,ParameterMode.IN);
String ret = (String) call.invoke( new Object[] {"20"} );
note the change in namespaceURI too.