How to call axis apache client in java

喜欢而已 提交于 2019-12-10 11:18:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4757741/how-to-call-axis-apache-client-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!