【问题标题】:How to call axis apache client in java如何在java中调用axis apache客户端
【发布时间】:2011-01-21 10:33:29
【问题描述】:

我想用java中的apache轴连接到web服务,我有一些错误的参数,但我不知道是哪个:

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());
    }
 }
}


网络服务链接:http://www.w3schools.com/webservices/tempconvert.asmx
在 ret 变量中,我收到消息错误。这是因为我在 QName 中有错误的参数吗?

【问题讨论】:

    标签: java web-services apache soap axis


    【解决方案1】:

    这是由于客户端代码和service.server之间的阻抗不匹配无法解码您的请求,并继续使用默认值处理

    你可以试试这个

    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"} );
    

    注意 namespaceURI 的变化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多