Friday, September 23, 2011

create webservice php with android exam



create web service php sever 
configureWSDL('hellowsdl',$ns);

 $server->wsdl->schemaTargetNamespace=$ns;

 // register a web service method
 $server->register('ws_add',
  array('int1' => 'xsd:integer','int2' => 'xsd:integer'),  // input parameters
  array('total' => 'xsd:integer'),        // output parameter
  $ns,               // namespace
  "$ns#ws_add",                        // soapaction
  'rpc',                                    // style
  'encoded',                                // use
  'adds two integer values and returns the result'            // documentation
  );

 function ws_add($int1, $int2){
  return new soapval('return','xsd:integer', ($int1 + $int2));
 }

 $server->register('hello',                // method name
  array('name' => 'xsd:string'),        // input parameters
  array('return' => 'xsd:string'),      // output parameters
  'urn:hellowsdl',                      // namespace
  'urn:hellowsdl#hello',                // soapaction
  'rpc',                                // style
  'encoded',                            // use
  'Says hello to the caller'            // documentation
 );

 function hello($name) {
   return 'Hello, ' . $name;
 }

 // service the methods
 $server->service($HTTP_RAW_POST_DATA);
?>

Android clien call webservice


package vn.softech.android;

import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class ClientCallWebServicesActivity extends Activity {
 private static final String SOAP_ACTION = "urn:hellowsdl#hello";
 private static final String METHOD_NAME = "hello";
 private static final String NAMESPACE = "urn:hellowsdl";
 private static final String URL = "http://192.168.73.177/nusoap/server.php";

//    private Object resultRequestSOAP = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

  // SoapObject
  request.addProperty("name", "Le Hong Vu");
  //call method ws_add
  //request.addProperty("int1", 3);
  //request.addProperty("int2", 4);

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);
  envelope.setOutputSoapObject(request);

  HttpTransportSE httpTransport = new HttpTransportSE(URL);
  httpTransport.debug = true;

  try {
   httpTransport.call(SOAP_ACTION, envelope);
   Object response = envelope.getResponse();
   Log.i("WSClient Result", response.toString());
  }

  catch (Exception exception) {
   Log.i("WSClient", exception.toString());
  }

    }
}
Link Download
http://www.ziddu.com/download/16485069/XMLRPCAndroidclient.rar.html

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.