0

Hello I am trying to solve this problem for past 5 hours now my web service use to work fine until I recently installed windows 8 and setup eclipse and android SDK.

My problem is that I added external jar ksoap and created a sample web service for the test.

When calling for the Soap response exception is created
"11-01 11:10:00.161: E/dalvikvm(304): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.example.testweb.MainActivity.Send"

Below is my xml code for the mainActvity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

   <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="194dp"
    android:text="TextView" />

  </RelativeLayout>

MainActivity.class

package com.example.testweb;


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;


public class MainActivity extends Activity {


 private static final String NAMESPACE = "http://tempuri.org/";
 private static final String URL = "http://10.0.2.2:34253/Service1.asmx"; 
 private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
 private static final String METHOD_NAME = "HelloWorld";




   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Send();
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
  }




   public void Send()
   {
     SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

         SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.dotNet=true;
       envelope.setOutputSoapObject(request);

       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 5000);

       try
       {
            androidHttpTransport.call(SOAP_ACTION, envelope);
           // SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

            SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
            //Hello World; }
            String result = resultsRequestSOAP.toString();
            Toast.makeText(this, result, Toast.LENGTH_LONG).show();

       }
       catch (Exception e) {
        // TODO: handle exception
           Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
    }

}

}

AndroidMenifest.XML

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.testweb"
  android:versionCode="1"
  android:versionName="1.0" >

  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

ScreenShot of the Ksoap.jar Ksoap Reference
enter image description here

My ASP.NET 3.5 Webservice code which i am running on localhost

/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment    the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
 }

I am using google api 8 and my ADT is 20.0.3 and my ksoap.jar is 2.6.5

Edit Guys my Jar problem is solved now a new error i am receiving which occurs on this link

    androidHttpTransport.call(SOAP_ACTION, envelope);

And the exception in the try catch gives me this error

     org.xmlpull.v1.XmlPullParserException: expected: START_TAG {schemas.xmlsoap.org/soap/envelope}Envelope (position:START_TAG <HTML>@2:7 in     java.io.InputStreamReader@44ef85f0)

Thanks in advance

Aftab Ali
  • 201
  • 1
  • 6
  • 16

4 Answers4

0

Download a fresh soap library & add to the project again.

Mario S
  • 11,715
  • 24
  • 39
  • 47
R World
  • 766
  • 9
  • 26
  • I already did that many times and i also added ksoap 3.0 but no difference. – Aftab Ali Nov 01 '12 at 07:00
  • @ rohit now all these error have occurred after downloading a new ksoap – Aftab Ali Nov 01 '12 at 07:11
  • @ nik i am having this problem now can you help "org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @2:7 in java.io.InputStreamReader@44ef85f0) " – Aftab Ali Nov 01 '12 at 07:30
0

I have same problem do like this problem solved.

Try to this

enter image description here

  • i am getting this error now "org.xmlpull.v1.XmlPullParserException: expected: START_TAG {schemas.xmlsoap.org/soap/envelope}Envelope (position:START_TAG @2:7 in java.io.InputStreamReader@44ef85f0)" – Aftab Ali Nov 01 '12 at 07:39
0

In the order and export setting try moving KSOP lib to top of the list.

EDIT 1: It looks like for some reason android not been able to connect to your sever and ksoap2 is not able to handle http response codes properly by default. it tries to parse a http error message like "file not found" and throws an exception as it is not valid SOAP. Try to use the ksoap2 source code in place of lib and check the http response code. source code is available at the this link..

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
  • @ praful no difference i am keep getting this in exception of try catch "org.xmlpull.v1.XmlPullParserException: expected: START_TAG {schemas.xmlsoap.org/soap/envelope}Envelope (position:START_TAG @2:7 in java.io.InputStreamReader@44ef85f0)" – Aftab Ali Nov 01 '12 at 08:17
  • So not its look like that library import issue is resolved and the problem is with the XML you are trying to parse. Please post the XML that you are parsing.. – Praful Bhatnagar Nov 01 '12 at 08:24
  • @ praful I already posted every xml in my original post . What I am trying to do is that I am just sending a request to my Web service, a method named HelloWorld and reading a response by that method which returns a string. i recieve this exception during " androidHttpTransport.call(SOAP_ACTION, envelope);" – Aftab Ali Nov 01 '12 at 08:46
  • it looks like from the logs that the response that is coming from server is not well formed XML. Is it possible for you to check the raw response coming form the server? – Praful Bhatnagar Nov 01 '12 at 08:55
  • @ Praful I am using the web service on localhost when I invoke it myself from the web service it gives a proper response. I don't know what's the problem here. – Aftab Ali Nov 01 '12 at 09:01
  • Is it somehow can you check the raw response from the web service? – Praful Bhatnagar Nov 01 '12 at 09:05
  • @ Praful can you tell me how to get the raw response because I haven't even done that before. – Aftab Ali Nov 01 '12 at 09:08
  • @ wireshark is too complicated for me and I don't have that much time I have to submit this by today.. Can you give me a alternate solution – Aftab Ali Nov 01 '12 at 10:56
  • Try using soap ui http://en.m.wikipedia.org/wiki/SoapUI to test your web service to see you are getting right response from web service.. – Praful Bhatnagar Nov 01 '12 at 12:27
  • @ praful I have successfully checked my web service by SoapUI and I am giving a link of the picture I took from the response and I am receiving correct response http://i1250.photobucket.com/albums/hh524/Aftab_Ali453/SOAP_result.png – Aftab Ali Nov 01 '12 at 17:14
  • It looks like for some resaon android not been able to connect to your sever and ksoap2 is not able to handle http response codes properly by default. it tries to parse a http error message like "file not found" and throws an exception as it is not valid SOAP. Try to use the ksoap2 source code in place of lib and check the http response code. source code is availale at the this http://code.google.com/p/ksoap2-android/wiki/SourceCodeHosting?tm=4 link.. Also I am assuming that you are trying the app on a emulator.. – Praful Bhatnagar Nov 01 '12 at 18:25
  • other people has also faced this issue http://supportforums.blackberry.com/t5/Java-Development/Please-Help-KSOAP2-Exception/td-p/381984 – Praful Bhatnagar Nov 01 '12 at 18:28
  • lots of other has also faced this issue when working with dotnet web server. check out this google search https://www.google.com/search?q=org.xmlpull.v1.XmlPullParserException%3A+expected%3A+START_TAG+%7Bschemas.xmlsoap.org%2Fsoap%2Fenvelope%7DEnvelope+(position%3ASTART_TAG&oq=org.xmlpull.v1.XmlPullParserException%3A+expected%3A+START_TAG+%7Bschemas.xmlsoap.org%2Fsoap%2Fenvelope%7DEnvelope+(position%3ASTART_TAG&sugexp=chrome,mod=0&sourceid=chrome&ie=UTF-8&qscrl=1 hope you might find something useful.. – Praful Bhatnagar Nov 01 '12 at 18:32
0

Guys I have solved my problem which is like below.

org.xmlpull.v1.XmlPullParserException: expected: START_TAG   {schemas.xmlsoap.org/soap/envelope}Envelope (position:START_TAG <HTML>@2:7 in   java.io.InputStreamReader@44ef85f0)

I was using web service created on .Net 3.5 used the IDE Visual studio 2012. But when I created the same service on Visual Studio 2010 SP1 I successfully received the response from the web service.. Apparently the solution which was posted on the internet about this same problem were not the right solution for most of the user's. Just rewrite your web service on 3.5 Using IDE Visual Studio 2010 SP1. You will receive the response.

Aftab Ali
  • 201
  • 1
  • 6
  • 16