SocketTimeoutException while calling webservice

963 views
Skip to first unread message

DD

unread,
Jun 4, 2011, 7:17:51 AM6/4/11
to ksoap2-android
hi friends,
i m trying to consume java webservice which returns array of objects
in android by using ksoap2-android-assembly-2.5.2-jar-with-
dependencies_timeout1.jar. But it throws exception SocketTimeout at
call.
i m using myeclipse9 and android3.0.

My wsdl code is

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://ws.demo/" targetNamespace="http://ws.demo/"
version="1.0">

<xs:element name="getAuthorName" type="tns:getAuthorName"/>

<xs:element name="getAuthorNameResponse"
type="tns:getAuthorNameResponse"/>

<xs:element name="getBookCode" type="tns:getBookCode"/>

<xs:element name="getBookCodeResponse"
type="tns:getBookCodeResponse"/>

<xs:element name="getBookName" type="tns:getBookName"/>

<xs:element name="getBookNameResponse"
type="tns:getBookNameResponse"/>

<xs:element name="getDetails" type="tns:getDetails"/>

<xs:element name="getDetailsResponse" type="tns:getDetailsResponse"/
>

<xs:element name="setAuthorName" type="tns:setAuthorName"/>

<xs:element name="setAuthorNameResponse"
type="tns:setAuthorNameResponse"/>

<xs:element name="setBookCode" type="tns:setBookCode"/>

<xs:element name="setBookCodeResponse"
type="tns:setBookCodeResponse"/>

<xs:element name="setBookName" type="tns:setBookName"/>

<xs:element name="setBookNameResponse"
type="tns:setBookNameResponse"/>

<xs:complexType name="getBookCode">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="getBookCodeResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setAuthorName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setAuthorNameResponse">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="getBookName">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="getBookNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setBookCode">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setBookCodeResponse">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="getAuthorName">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="getAuthorNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="getDetails">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="getDetailsResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return"
nillable="true" type="tns:bookBean"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="bookBean">
<xs:sequence>
<xs:element minOccurs="0" name="authorName" type="xs:string"/>
<xs:element name="bookCode" type="xs:int"/>
<xs:element minOccurs="0" name="bookName" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setBookName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="setBookNameResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>

_______________________________________________________

My Android client is

package sample.ws;

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

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AnBookWSActivity extends Activity {
/** Called when the activity is first created. */
private String METHOD_NAME = "getDetails";


private String SOAP_ACTION = "http://demo.ws/" + METHOD_NAME; // here
your package name in webservice but in reverse order + methodname
private String NAMESPACE ="http://demo.ws"; // Here package name in
webservice with reverse order.
private static final String URL = "http://192.168.1.45:8080/BookWSPrj/
BookBeanPort"; // you must use ipaddress here, don’t use Hostname or
localhost

private ListView lv1;

/** Called when the activity is first created. */

@SuppressWarnings({ "deprecation", "deprecation", "deprecation" })
public void onCreate(Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.main);



try {
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

BookBean C = new BookBean();
C.authorName="wrox";

PropertyInfo pi = new PropertyInfo();
pi.setName("C");
pi.setValue(C);
pi.setType(C.getClass());
request.addProperty(pi);

SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false; // for calling asp.net webservice


envelope.setOutputSoapObject(request);

/*********************** Adding the mapping for the class
*************/
envelope.addMapping(NAMESPACE,"BookBean",new BookBean().getClass());


HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

System.out.println("---before call");

androidHttpTransport.debug = true;
System.out.println("request xml : " +
androidHttpTransport.requestDump);
System.out.println("response xml : " +
androidHttpTransport.responseDump);

androidHttpTransport.call(SOAP_ACTION,envelope);


System.out.println("after request xml : " +
androidHttpTransport.requestDump);
System.out.println("after response xml : " +
androidHttpTransport.responseDump);

/************************************/

SoapObject result= (SoapObject) envelope.getResponse();

System.out.println("&&&&&&& after envelope response");
BookBean[] blist = RetrieveFromSoap(result);


/****************** Setting List to Listview ************/

lv1=(ListView)findViewById(R.id.ListView01);
// By using setAdpater method in listview we an add string array in
list.
lv1.setAdapter(new
ArrayAdapter<BookBean>(this,android.R.layout.simple_list_item_1 ,
blist));


/*********************************************************/

} catch (Exception E) {
E.printStackTrace();

}
}



/*********************** Imp Code for retriving list result in android
****/
/****** Method to retrieve list from SoapObject ********/

public static BookBean[] RetrieveFromSoap(SoapObject soap)
{
BookBean[] books = new BookBean[soap.getPropertyCount()];
for (int i = 0; i < soap.getPropertyCount(); i++) {
SoapObject pii = (SoapObject)soap.getProperty(i);
BookBean bk = new BookBean();
bk.bookCode = Integer.parseInt(pii.getProperty(0).toString());
bk.BookName =pii.getProperty(1).toString();
System.out.println("$$$$4"+bk.BookName);
bk.authorName=pii.getProperty(2).toString();
books[i] = bk;
}
return books;
}

/***********************************************************/

}

____________________________


and my BookBean on android side is

package sample.ws;


import java.util.Hashtable;


import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class BookBean implements KvmSerializable {

int bookCode;
String BookName;
String authorName;

public BookBean()
{}

public BookBean(int bcode,String bname,String aname)
{
bookCode=bcode;
BookName=bname;
authorName=aname;
}

public int getBookCode()
{
return bookCode;
}

public void setBookCode(int bcode)
{
bookCode=bcode;
}

public String getBookName()
{
return BookName;
}

public void setBookName(String bname)
{
System.out.println("^^^^^");
BookName=bname;
}

public String getAuthorName()
{
return authorName;
}

public void setAuthorName(String aname)
{
authorName=aname;
}


@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch(arg0)
{
case 0:
return bookCode;
case 1:
return BookName;
case 2:
return authorName;
}

return null;


}

@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 3;
}

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo
info) {
// TODO Auto-generated method stub
switch(index)
{
case 0:
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "bookCode";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "BookName";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "authorName";
break;
default:break;
}

}

@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
switch(index)
{
case 0:
bookCode = Integer.parseInt(value.toString());
break;
case 1:
BookName = value.toString();
break;
case 2:
authorName = value.toString();
break;
default:
break;
}

}
}

__________________________________________

webservice fetches proper result at javaend but it throws
SocketTimeoutException at
androidHttpTransport.call(SOAP_ACTION,envelope);

pls. help....got stuck on this problem from past few days......

Thanx

Naveen Balani

unread,
Jun 5, 2011, 1:32:45 AM6/5/11
to ksoap2-...@googlegroups.com
If you are running this via the emulator, probably the emulator could
be blocking connections. Have a look at the blog -
http://naveenbalani.com/index.php/2011/01/invoke-webservices-from-android/
. I got some unknown host and security issues which i had documented
in the blog while running it via the emulator and may be your issue
could be manifestation of that. Also look at
http://developer.android.com/guide/developing/tools/emulator.html#networkinglimitations
for limitations on using the emulator.

- Naveen

Manfred Moser

unread,
Jun 6, 2011, 3:22:43 PM6/6/11
to ksoap2-...@googlegroups.com
And please note that this as well as other useful blog entries are all linked on the wiki for you to read and check out.
http://code.google.com/p/ksoap2-android/wiki/Links

DD

unread,
Jun 7, 2011, 6:56:15 AM6/7/11
to ksoap2-android
hi..
after adding ksoap2-android-assembly-2.5.5-jar-with-dependencies.zip
in build path, sockettimedout exception resolved but now it throws
fatal exception--No class definition found --SoapObject

pls.help


On Jun 7, 12:22 am, Manfred Moser <mosa...@gmail.com> wrote:
> And please note that this as well as other useful blog entries are all
> linked on the wiki for you to read and check out.http://code.google.com/p/ksoap2-android/wiki/Links
>
> On Sat, Jun 4, 2011 at 10:32 PM, Naveen Balani <naveenbal...@gmail.com>wrote:
>
>
>
> > If you are running this via the emulator, probably the emulator could
> > be blocking connections. Have a look at the blog -
> >http://naveenbalani.com/index.php/2011/01/invoke-webservices-from-and...
> > . I got some unknown host and security issues which i had documented
> > in the blog while running it via the emulator and may be your issue
> > could be manifestation of that. Also look at
>
> >http://developer.android.com/guide/developing/tools/emulator.html#net...
> > for limitations on using the emulator.
>
> > - Naveen
>
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Manfred Moser

unread,
Jun 7, 2011, 10:39:07 AM6/7/11
to ksoap2-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages