简体   繁体   中英

How to call one specific method of Webservice from Client in Android

I am stuck in calling this specific method:

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

of my Webservice configured in my localhost. I need to send parameters from client and get the return value. I dont know how to make this call. I can succefully call the WSDL file of my webservice from android client. Please help me to know how can I send a call to this method along with two parameters of type Int and then get the resulted value of double [] [] .

If using Java use ArrayList<MyClass> where MyClass is having two Integer variables.

Use Jersey for Restful webServices.

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;
    }
}

From Client you have to call your_services_name , for after call your_operation_name (it is a method, so you will call it, passing your parameters... kind of: your_operation_name(int1, int2) ). Your Web Services recieve the call (with the two parameters) and returns your_value_to_returns

this is the Webservice Class.

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);
}

}

and this one is the next class of webservice.

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;
 }
}

I am done with Http Call. Its working fine. How to make call that webservice return the arraList to android.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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