3 Temmuz 2013 Çarşamba

how can i connect to webservice from android

hi.

    private static String SOAP_ACTION = "http://tempuri.org/HelloWorld";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String METHOD_NAME = "HelloWorld";
    private static final String URL = "http://192.168.1.3:80/tryAndoridWebService/serviceTest.asmx?WSDL";

    Button btnConnectWebServis;
    EditText txtGetData;

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        btnConnectWebServis= (Button)findViewById(R.id.btnConnectWebServis);
        txtGetData= (EditText)findViewById(R.id.txtGetData);


        btnConnectWebServis.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //Initialize soap request + add parameters
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                //Use this to add parameters
                request.addProperty("param1","my parameter");// send parameter to webservice

                //Declare the version of the SOAP request
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

                envelope.setOutputSoapObject(request);
                envelope.dotNet = true;

                try {
                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                    StrictMode.setThreadPolicy(policy);
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    if (envelope.bodyIn instanceof SoapFault) {
                        String str= ((SoapFault) envelope.bodyIn).faultstring;
                        txtGetData.setText(str);
                        Log.i("", str);
                    } else {
                        SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                        Log.d("WS", String.valueOf(resultsRequestSOAP));
                        txtGetData.setText(String.valueOf(resultsRequestSOAP.getProperty(0).toString()));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "hata : "+e.getMessage(),Toast.LENGTH_LONG).show();
                }
            }
        });
}

one more thing
add your manifest.xml file
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />

AND 
run this code on your adb console
 adb forward tcp:8080 tcp:8080

Download Picture as .zip file on asp.net mvc

you must download this dll -- Ionic.Zip.dll

////////////////////////////// Then we have create or picture class //////////////////////////

public class cPicture
    {
        public int CID { get; set; }
        public int AlbumID { get; set; }
        public int DosyaID { get; set; }
        public string name { get; set; }
        public double size { get; set; }
        public string type { get; set; }
        public string url { get; set; }
        public string delete_url { get; set; }
        public string thumbnail_url { get; set; }
        public string delete_type { get; set; }
        public string Tag { get; set; }
    }

///////////////// then we are creating new class ///////////////////////////////////

public class ZipResult : ActionResult
    {
        private IEnumerable<string> _files;
        private string _fileName;

        public string FileName
        {
            get
            {
                return _fileName ?? "file.zip";
            }
            set { _fileName = value; }
        }

        public ZipResult(params string[] files)
        {
            this._files = files;
        }

        public ZipResult(IEnumerable<string> files)
        {
            this._files = files;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            using (ZipFile zf = new ZipFile())
            {
                zf.AddFiles(_files, false, "");
                context.HttpContext
                    .Response.ContentType = "application/zip";
                context.HttpContext
                    .Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
                zf.Save(context.HttpContext.Response.OutputStream);
            }
        }
    }

/// Now we are creating or ActionResult for download/////////////////////
public ActionResult DownloadPicture()
        {
            
                IEnumerable<cPicture> pictures = // our cPictureList
                string basePath = Server.MapPath("~/UserFiles/");
                IEnumerable<string> pp = pictures.Select(a => Path.Combine(basePath, a.name)).ToArray();

                return new ZipResult(pp);
        }


<a href="/Home/DownloadPicture/" target="_blank">Download File</a>

Yeah That's it.