简体   繁体   English

从Java客户端向Web服务传递数字参数的问题

[英]problem with passing numeric parameter to web service from java client

i try to passing numeric parameter to a web service that receive the value and return it back. 我尝试将数值参数传递给接收该值并将其返回的Web服务。 this is the snippet of the web method : 这是web方法的代码段:

@WebMethod(operationName = "getNumber")
public Integer getNumber(@WebParam(name = "i")
Integer i) {
    //TODO write your implementation code here:
    System.out.println("number : "+i);
    return i;
}

an this is the snippet of my client code : 这是我的客户代码的片段:

    Map results = FastMap.newInstance();
    results.put("result", "success");

    String endPoint = "http://localhost:8084/ProvideWS/MathWS";
    URL endpoint=null;
    try{
        endpoint = new URL(endPoint);
    }
    catch (MalformedURLException e) {
        org.ofbiz.base.util.Debug.log("Location not a valid URL "+e);
        // TODO: handle exception
    }
    Service service = null;
    Call call = null;
    try{
        service = new Service();

        call = (Call)service.createCall();
        call.setTargetEndpointAddress(endpoint);
        String nameSpace = "http://ws/";

        String serviceName = "getNumber";

        call.setOperationName(new QName(nameSpace, serviceName));

        call.addParameter("i",org.apache.axis.Constants.XSD_INTEGER , ParameterMode.IN);
        call.setReturnType(org.apache.axis.Constants.XSD_INTEGER);

        Object msg[] = new Object[]{new Integer(5)};    
        for (Object o : msg) {
            org.ofbiz.base.util.Debug.log("object to be sent===== "+o.toString());
        }
        Object ret = call.invoke(msg);
        results.put("result", "result : "+ ret.toString());

    }
    catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        org.ofbiz.base.util.Debug.log("exc when running soap client test : "+e);
        results.put("result", "error : "+e);
    }
    return results;

the problem is the return value in the client always 0 (the server received the number as zero), the method i used to pass the parameter works fine when the paramater is String. 问题是客户端中的返回值始终为0(服务器接收到的数字为零),当参数为String时,我用于传递参数的方法可以正常工作。 I.ve tried to hard-coding the return value in server and the output in client is fine, so i thought it must be how the server retrieved the parameter is the problem. 我试图硬编码服务器中的返回值,客户端中的输出很好,所以我认为这一定是服务器检索参数的方式。

do you have any idea why this is happen and how to solve this? 您是否知道为什么会这样以及如何解决这个问题?

any help will be appreciated, thanks 任何帮助将不胜感激,谢谢

I don't know what is causing your problem. 我不知道是什么引起您的问题。 But the first thing I would do would be to try to capture the actual request that is being sent to the server. 但是,我要做的第一件事就是尝试捕获发送到服务器的实际请求。 That should give you some clues as to whether the root problem is on the client or server side. 这应该为您提供根本问题是在客户端还是在服务器端的一些线索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM