从 java 客户端将数字参数传递到 Web 服务时出现问题

发布于 2024-10-15 07:39:41 字数 1880 浏览 7 评论 0原文

我尝试将数字参数传递给接收该值并将其返回的网络服务。 这是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;
}

这是我的客户端代码的片段:

    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;

问题是客户端中的返回值始终为0(服务器接收到的数字为零),我用来传递参数的方法工作正常当参数为字符串时。我尝试对服务器中的返回值进行硬编码,并且客户端中的输出很好,所以我认为问题一定是服务器检索参数的方式。

您知道为什么会发生这种情况以及如何解决这个问题吗?

任何帮助将不胜感激,谢谢

i try to passing numeric parameter to a web service that receive the value and return it back.
this is the snippet of the web method :

@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. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千鲤 2024-10-22 07:39:41

我不知道是什么导致了你的问题。但我要做的第一件事是尝试捕获发送到服务器的实际请求。这应该可以为您提供一些线索,以确定根本问题是在客户端还是服务器端。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文