title: Calling webservice asp.net from Android
body: <p>I am having problems in connecting to a web service I have created. 
  When I try to call the webservice from my Android Code it doesn't work but when I manually write the request with variables passed in the address bar it works. 
  Please have a look at the code. I think the problem is with the function that I am calling on pageload, it doesn't work when I call it through Android. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.Script.Serialization;
  using System.Web;
  using System.Data.SqlClient;
  using System.Collections;
  
  namespace MyService
  {
      public partial class Caller : System.Web.UI.Page
      {
          //public int a, b;
          protected void Page_Load(object sender, EventArgs e)
          {
              this.txtBox1.Text = Request.QueryString["Name"];
              this.txtBox2.Text = Request.QueryString["Price"];
              if (txtBox1.Text != "" &amp;&amp; txtBox2.Text != "")
                  Add(txtBox1.Text, Convert.ToInt32(txtBox2.Text));  
  
          }
  
          public void Add(String name, int price)
          {
              //this.txtBox1.Text = Request.QueryString["Name"];
              //this.txtBox2.Text = Request.QueryString["Price"];
              SqlConnection con = new SqlConnection(util.ConnectionString);
              con.Open();
              String query = "insert into Cart values ('" + name + "',"+ price +");";
              SqlCommand cmd = new SqlCommand(query, con);
              SqlDataReader reader = cmd.ExecuteReader();
              reader.Read();
          } 
      }
  }
  </code></pre>
  
  <p>Ok! When I have hosted the website on IIS and type the query in the address bar it works for example 192......../MyAndroid/Caller.aspx?Name=Banana&amp;Price=15 
  This is working fine but when calling from android its not working. 
  Here is the android code. </p>
  
  <pre><code>try {                   
                              Connectivity c = new Connectivity();    
                              String Name = holder.txtItemName.getText().toString();
                              int Price = Integer.parseInt((String)holder.txtPrice.getText());
                              String url="http://192.168.15.2/MyAndroid/Caller.aspx?Name="+Name+"&amp;Price="+Price; //do not use localhost
                              String response=c.callWebService(url);
                              } catch (Exception e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                              }
  </code></pre>
  
  <p>A little help would be appreciated. Thank you!!</p>
  
  <p>Android Manifest file </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.quiz.activities"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="10" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
  
          &lt;activity
              android:name=".QuizActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
  
          &lt;activity            
              android:name=".Add" 
              android:label="@string/app_name" &gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.Add" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
          &lt;activity            
              android:name=".Get" 
              android:label="@string/app_name" &gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.Get" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;/manifest&gt;
  </code></pre>