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.

27 Haziran 2013 Perşembe

Android Socket programming connection failed

if there  is connection failed on your app you must run this command from console

                    adb forward tcp:8080 tcp:8080

each of this tcp:8080 is your server port and client port number.



1 Haziran 2013 Cumartesi

DEVEXPRESS Use Cascade Combobox in İnline Edit Mode

<dx:GridViewDataComboBoxColumn FieldName="Category1ID" VisibleIndex="4">
                    <PropertiesComboBox DataSourceID="dsCategory1" TextField="Name" ValueField="ID" ValueType="System.Int32">
                    </PropertiesComboBox>
                    <EditItemTemplate>
                            <dxe:ASPxComboBox ID="Cat1" runat="server"
                            DataSourceID="dsCategory1"  TextField="Name" ValueField="ID" Value='<%# Bind("Category1ID") %>'
                            AutoPostBack="true" OnSelectedIndexChanged="Cat1_SelectedIndexChanged" ValueType="System.Int32">
                            </dxe:ASPxComboBox>
                    </EditItemTemplate>
                </dx:GridViewDataComboBoxColumn>

------------------------------------------------------------------------------------------------------------

protected void grid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if ((e.RowType == GridViewRowType.InlineEdit)) {
                ASPxComboBox combo2 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category2ID"] as GridViewDataComboBoxColumn, "Cat2"));
                if (Request.Params[combo2.UniqueID] != null) return;

                if (!grid.IsNewRowEditing) {
                    object[] vals = (object[])grid.GetRowValues(grid.EditingRowVisibleIndex,
                    new string[] { "Category2ID", "Category3ID", "Category4ID" });
                    ASPxComboBox combo4 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category4ID"] as GridViewDataComboBoxColumn, "Cat4"));
                    ASPxComboBox combo3 = ((ASPxComboBox)grid.FindEditRowCellTemplateControl(
                    grid.Columns["Category3ID"] as GridViewDataComboBoxColumn, "Cat3"));
                    combo2.Value = vals[0];
                    combo3.Value = vals[1];
                    combo4.Value = vals[2];
                }
            }
        }

31 Mayıs 2013 Cuma

DEVEXPRESS ASPxGridView PropertiesComboBox DataSource On CodeBehind

<dx:ASPxGridView ID="GridViewTRY" runat="server"  DataSourceID="SDSGridViewTRY" KeyFieldName="ID" OnInit="GridViewTRY_Init">
        <Columns>                                  
              <dx:GridViewDataComboBoxColumn FieldName="PersonalFK" Caption="Personel Adı" ShowInCustomizationForm="True" >
                      <PropertiesComboBox TextField="PersonelName" ValueField="ID"></PropertiesComboBox>
                       </dx:GridViewDataComboBoxColumn>            
          </Columns>
</dx:ASPxGridView>

                           //                        on CodeBehind             //                          

protected void GridViewTRY_Init(object sender, EventArgs e)
{
   ASPxGridView gridView = (ASPxGridView)sender;
   ((GridViewDataComboBoxColumn)(gridView.Columns["PersonelFK"])).PropertiesComboBox.DataSource = myPersonalList;
}

30 Mayıs 2013 Perşembe

pass null parameter if Selectparameter is null

<asp:SqlDataSource ID="SDStry" runat="server" CancelSelectOnNullParameter="false"
SELECTCommand="SELECT  * FROM tbFirma WHERE KisiFK=ISNULL(@KisiFK,KisiFK)">

<SelectParameters>
        <asp:Parameter Name="KisiFK" ConvertEmptyStringToNull="true" />
</SelectParameters>

</asp:SqlDataSource>