0

I am newbie to android development. I am using android studio for developing an app. I know there are lot and lot of questions related to it, i looked into them but my problem still exists. Below are the solutions in which i have looked into.

  1. link1
  2. link2
  3. link3

I clearly looked into them and match with my problem. But still i am unable to solve my issue.

The app is simple that will have a editText a button and a textView. User should enter id in editText and when the button is tapped then the corresponding name should be shown. The button will use a webservice.

For this i created some tables in SQL. And created a webservice in dotnet.

Below is my web service

[WebMethod]

public string findContact(string eid)
{
    return getContact(eid);
}

public string getContact(string eid)
{

    SqlConnection conn;

    conn = ConnectionManager.GetConnection();
    conn.Open();

    SqlCommand newCmd = conn.CreateCommand();

    newCmd.CommandType = CommandType.Text;

    newCmd.CommandText = "Select Name from Users where Id=" + eid + "";

    SqlDataReader sdr = newCmd.ExecuteReader();

    String address = null;

    if(sdr.Read())
    {
        address = sdr.GetValue(0).ToString();
    }

    conn.Close();
    return address;
}

Below is my manifest file

 <uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Below is my java code

public class MainActivity extends AppCompatActivity {

/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/findContact";
private static final String METHOD_NAME = "findContact";// webservice web method name
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.100.9:9698/WebService.asmx";

TextView textView;
Button button;
EditText editText;

String ID;
public static final String LOG_TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    textView = (TextView)findViewById(R.id.webServ);
    button = (Button)findViewById(R.id.btnSubmit);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

            PropertyInfo propertyInfo = new PropertyInfo();
            propertyInfo.type = PropertyInfo.STRING_CLASS;
            propertyInfo.name = "eid";

            editText = (EditText)findViewById(R.id.enterID);

            ID = editText.getText().toString();

            request.addProperty(propertyInfo,ID);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);

            HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
            httpTransportSE.debug = true;
            try
            {
                httpTransportSE.call(SOAP_ACTION,envelope);
                Object response = envelope.getResponse();
                textView.setText(response.toString());

            } catch (XmlPullParserException e) {

                textView.setText(e.toString() + " Or enter ID is not valid!");

                e.printStackTrace();
            } catch (IOException e) {
                textView.setText(e.toString() + " IOException Or enter ID is not valid!");
                e.printStackTrace();
            }

            String res = (httpTransportSE.responseDump).toString();
            Log.v(LOG_TAG, res);
        }
    });
}}

When i click on the button i am getting the bellow error.

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <HTML>@2:7 in java.io.InputStreamReader@960e1fa) 
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at org.kxml2.io.KXmlParser.require(KXmlParser.java:2065)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at com.example.accurat.accesswebservice.MainActivity$1.onClick(MainActivity.java:75)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.view.View.performClick(View.java:4780)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.view.View$PerformClick.run(View.java:19866)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
02-10 12:20:50.994 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.os.Looper.loop(Looper.java:135)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-10 12:20:50.995 11713-11713/com.example.accurat.accesswebservice W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

It hits at the line httpTransportSE.call(SOAP_ACTION,envelope);

I am testing it on the emulator, below is the screen shot of my emulator

enter image description here

I have also checked my Webservice running in web browser, it's working fine. But it's not on the emulator.

Any help would be highly appreciated.

Community
  • 1
  • 1
Moeez
  • 494
  • 9
  • 55
  • 147

0 Answers0