4
votes

I have some code which is working in iphone and i want to make same application in android. i must use php webservice. using soap library. i want to use following webservice http://www.medihand.org/freechoicedrivers/soap/members.php

it is wsdl code here

− − − − − − − − − − − −

and i used android code which i put here

public class start extends Activity {

private static final String SOAP_ACTION = "urn:members#syncMemberDetails";

 private static final String METHOD_NAME = "syncMemberDetails";

 private static final String NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";

 // !!!!! IMPORTANT!!!!! THE URL OF THE CoLDFUSION WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!

 private static final String URL = "http://www.medihand.org/freechoicedrivers/soap/members.php";

 //String sample[] ={"milan","pratik"}; 

 TextView tv;

 String s="";

 @Override

 public void onCreate(Bundle icicle) {

     super.onCreate(icicle);

     setContentView(R.layout.main);


  /*   s = " <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
        "<SOAP-ENV:Envelope\n"+
        " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"+
       " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"+
       " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"+
       " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"+
       " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"+
       "  <SOAP-ENV:Body>\n"+
       "    <syncMemberDetails>\n"+
       "      <values xsi:type=\"xsd:Array\">\n"+
       "        <item>\n"+
       "          <username xsi:type=\"xsd:string\">test</username>\n"+
       "          <password xsi:type=\"xsd:string\">test</password>\n"+
       "          <dates xsi:type=\"xsd:Array\">\n"+
       "            <item>\n"+
       "              <year xsi:type=\"xsd:int\">2010</year>\n"+
       "              <month xsi:type=\"xsd:int\">12</month>\n"+
       "              <day xsi:type=\"xsd:int\">%30</day>\n"+
       "              <sync xsi:type=\"xsd:int\">(null)</sync>\n"+
       "              <times xsi:type=\"xsd:Array\">\n"+
       "                <item>\n"+
       "                  <start xsi:type=\"xsd:int\">0</start>\n"+
       "                  <finish xsi:type=\"xsd:int\">0</finish>\n"+
       "                  <sync xsi:type=\"xsd:int\">0</sync>\n"+
       "                  <timestamp xsi:type=\"xsd:date\">2010-11-10 18:07:44 GMT</timestamp>\n"+
       "                </item>\n"+
       "              </times>\n"+
       "            </item>\n"+
       "            <item>\n"+
       "    <year xsi:type=\"xsd:int\">2010</year>"+
       "    <month xsi:type=\"xsd:int\">12</month>"+
       "    <day xsi:type=\"xsd:int\">21</day>"+
       "    <sync xsi:type=\"xsd:int\">0</sync>"+
       "    <times xsi:type=\"xsd:Array\">"+
       "   </times>"+
       "   </item>"+
       "          </dates>\n"+
       "        </item>\n"+
       "      </values>\n"+
       "    </syncMemberDetails>\n"+
       "  </SOAP-ENV:Body>\n"+
       "</SOAP-ENV:Envelope>";*/




     tv = (TextView) findViewById(R.id.title);

  SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
  Request.addProperty("?????", "array value");


     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

     envelope.setOutputSoapObject(Request);

     AndroidHttpTransport aht = new AndroidHttpTransport (URL);                    

     try {

      aht.call(SOAP_ACTION, envelope);
    SoapPrimitive resultstring = (SoapPrimitive) envelope.getResponse();

     Toast.makeText(this, String.valueOf(resultstring), 5000).show();



     } catch(Exception E) {

           tv.setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());

     }

} }

what i have to write in request.addProperty(????,"value")

in dotnew web service i used tag where ? here....so any one know plz tell me how can i access this php webservice

i also put iphone code which is already running

1

1 Answers

2
votes

use this code and appropriate changes(include ksoap library)

     String url="http://192.168.1.163/webservice/test.php";
    String namespace="http://tempuri.org";
       String method="getuser";
    SoapObject request=new SoapObject(namespace,method);
    request.addProperty("u","admin"); ***//paraemeter of method(u is php method parametr)***
    request.addProperty("i","icare"); **/*/paraemeter of method***
    SoapSerializationEnvelope soapEnvelope=new SoapSerializationEnvelope(SoapEnvelope.VER10);

    soapEnvelope.setOutputSoapObject(request);
    AndroidHttpTransport ahi=new AndroidHttpTransport(url);
    try
    {
    ahi.call(soapaction,soapEnvelope);  
    SoapPrimitive response=(SoapPrimitive)soapEnvelope.getResponse();




    }
    catch(Exception e)
    {
        e.printStackTrace();
    }