如何在Android中从Client调用一个特定的Webservice方法

时间:2016-05-29 16:30:28

标签: javascript android web-services rest

我被困在调用这个特定的方法:

public double[][] Multi(double a [][], double b[][]){
        return bimpl.Multi(a, b);
}
我在我的localhost中配置的Web服务的

。我需要从客户端发送参数并获取返回值。我不知道怎么打这个电话。我可以从android客户端成功调用我的webservice的WSDL文件。请帮助我了解如何向此方法发送调用以及Int类型的两个参数,然后获取double [] []的结果值。

3 个答案:

答案 0 :(得分:2)

如果使用Java,请使用ArrayList<MyClass>,其中MyClass有两个整数变量。

将Jersey用于Restful webServices。

答案 1 :(得分:1)

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "your_services_name")
public class your_services_name {

    @WebMethod(operationName = "your_operation_name")
    public String descripcion(@WebParam(name = "your_int1") int your_int1, @WebParam(name = "your_int2") int your_int2) {
        // DO YOUR STUFF. CALL ANOTHER PRIVATE METHOD AND SO ON...
        String json = new Gson().toJson(your_value_to_returns);
        return json;
    }
}

从客户端,您必须致电 your_services_name ,以便通过电话 your_operation_name (这是一种方法,因此您将调用它,传递您的参数......种类: your_operation_name(int1,int2))。您的Web服务接收呼叫(使用两个参数)并返回 your_value_to_returns

答案 2 :(得分:0)

这是Webservice类。

package org.ali.javabrains;

import java.util.List;
import javax.jws.WebService;
import org.ali.javabrains.BusinessImpl.BusinessImpl;

@WebService
public class ProductCatalog {

BusinessImpl bimpl=new BusinessImpl();

public List<String> getProductCategories(String category){
    return bimpl.getProductCategories();
}

public List<String> getProduct(String category){
    return bimpl.getProduct(category);

}

public void RandomArray(int n) {

}

public void RandomArray1(int n) {

}
public double[][] Multi(double a [][], double b[][]){
    return bimpl.Multi(a, b);
}

}

这个是下一类web服务。

public class BusinessImpl {

double [][] a;
double [][] b;

public void RandomArray(int n) {
        double[][] randomMatrix = new double[n][n];
        double[] randomArray = new double[n];
        Random rand = new Random();
        rand.setSeed(System.currentTimeMillis());

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {
                Integer r = rand.nextInt() % 100;
                randomMatrix[i][j] = Math.abs(r);
            }
        }
         a= randomMatrix;
    }

  public void RandomArray1(int n) {
        double[][] randomMatrix1 = new double[n][n];
        double[] randomArray = new double[n];
        Random rand = new Random();
        rand.setSeed(System.currentTimeMillis());

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {
                Integer r = rand.nextInt() % 100;
                randomMatrix1[i][j] = Math.abs(r);
            }
        }
           b = randomMatrix1;

           Multi(a,b);
    }

  public double[][] Multi(double a [][], double b[][]){//a[m][n], b[n][p]
     if(a.length == 0) return new double[0][0];
     if(a[0].length != b.length) return null; //invalid dims

     int q = a[0].length;
     int m = a.length;
     int p = b[0].length;

     double ans[][] = new double[m][p];

     for(int i = 0;i < m;i++){
         for(int j = 0;j < p;j++){
             for(int k = 0;k < q;k++){
                 ans[i][j] += a[i][k] * b[k][j];
             }
         }
     }

     return ans;
 }
}

我完成了Http Call。它的工作正常。如何调用webservice将arraList返回给android。

相关问题