簡體   English   中英

從Java客戶端向Web服務傳遞數字參數的問題

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

我嘗試將數值參數傳遞給接收該值並將其返回的Web服務。 這是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(服務器接收到的數字為零),當參數為String時,我用於傳遞參數的方法可以正常工作。 我試圖硬編碼服務器中的返回值,客戶端中的輸出很好,所以我認為這一定是服務器檢索參數的方式。

您是否知道為什么會這樣以及如何解決這個問題?

任何幫助將不勝感激,謝謝

我不知道是什么引起您的問題。 但是,我要做的第一件事就是嘗試捕獲發送到服務器的實際請求。 這應該為您提供根本問題是在客戶端還是在服務器端的一些線索。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM