Six steps are required. For the NAME_SPACE in the code below, you can connect to the server through a software SoapUI.
/** Namespace. */private final static String NAME_SPACE = urn: soap;/** method. */private final static String METHOD_NAME = Add;/** URL of the WSDL file. */private final static String WSDL_URL = http: // 192.168.1.112: 80/index. php/service? Wsdl;
// 1. Specify the WebService namespace and the called method name SoapObject request = new SoapObject (NAME_SPACE, METHOD_NAME );
// 2. this step is optional. If the method does not have any parameters, You can omit this step. addProperty (a, 123); request. addProperty (B, 12 );
// 3. Generate the SOAP request information that calls the WebService method. This information is described by the SoapSerializationEnvelope object SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope. VER10); envelope. bodyOut = request;
// 4. Create an HttpTransportSE object. Through the construction method of the HttpTransportSE class, you can specify the URL HttpTransportSE ht = new HttpTransportSE (WSDL_URL) of the WSDL document of WebService; ht. debug = true;
// 5. Use the call method to call the WebService Method
List headerList =ht.call(null, envelope,null);
Note: If you do not need a header file, you only need to pass the first two parameters.
// 6. use the getResponse method to obtain the returned results of the WebService method SoapObject result = (SoapObject) envelope. bodyIn; Log. I (=========, result. getProperty (Add ). toString ());