简体   繁体   中英

How to create a web service with method taking two parameters

For example, I have to create a webservice with a details below:

Webservice name is WS1 Method name is initiateBatchProcess (String Status, int BatchID)

I have tried the following with one parameter, but how do I do it with two parameters and return it in the response of webservice/soap

public class WS1 
{
    int status;

    @WebMethod(operationName="status")
    public int status(int status) {
        return status;
    }
}

You simply add another parameter. The use of the @WebParam is optional, keep it if you want or ditch it.

@WebMethod(operationName="initBatch")
public void initiateBatchProcess(@WebParam(name = "Status") String Status, 
                   @WebParam(name = "Batch") int BatchID) {
      //do stuff
}

LE:

So, if you want to send back more than one thing, the best solution i can think of is encapsulating those things into a single object.

@WebMethod(operationName="initBatch")
public RezultSet initiateBatchProcess(String status, int batchID) {

      //do stuff

    ResultSet result = new ResultSet();
    result.setStatus(status);
    result.setBatchId(batchID);
    return result;
    /*
    *Or you can do something like 
    *return new ResultSet(status, batchID);
    */

}

And ResultSet is just a simple bean with 2 members.

public class ResultSet {

    private String status;
    private int batchID;

    // getters, setters, constructors

}

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