如何轴在Java的Apache客户端调用 [英] How to call axis apache client in java

查看:142
本文介绍了如何轴在Java的Apache客户端调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到在Java Apache Axis的web服务,我有一些错误的参数,但我不知道是哪个:

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服务的链接: http://www.w3schools.com/webservices/ tempconvert.asmx

在RET变量,我得到消息错误。这是因为我在错误的QName参数。


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.

推荐答案

这是由于阻抗不匹配beetween客户code和service.server不能去code您的要求,继续处理使用默认值

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

您可以试试这个代替

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变化了。

note the change in namespaceURI too.

这篇关于如何轴在Java的Apache客户端调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆