ksoap2 : java.lang.IllegalArgumentException: size <= 0 while making a http.call
Asked Answered
A

4

6

I want to connect to a dot.net based Webservice with my Android 4.03 Device using Ksoap2.

My problem is when i call the soap request i get this exception:

11-16 08:35:08.649: W/System.err(6392): java.lang.IllegalArgumentException: size <= 0
11-16 08:35:08.649: W/System.err(6392): at java.io.BufferedInputStream.<init>(BufferedInputStream.java:94)
11-16 08:35:08.649: W/System.err(6392): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:226)
11-16 08:35:08.649: W/System.err(6392):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
11-16 08:35:08.649: W/System.err(6392):     at at.jesenko.eDoc.MainActivity$1.run(MainActivity.java:48)

The Code im using

    final String url = "http://server:9007/DWService?wsdl";
    final String NAMESPACE = "http://tempuri.org/";
    final String METHOD_NAME ="Login";
    final String SOAP_ACTION="http://tempuri.org/Login";

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

    Thread loginThread = new Thread(){

            @Override
            public void run() {

                try {


                    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
                    Request.addProperty("userName", "demo");
                    Request.addProperty("password", "demo1234");
                    Request.addProperty("organization", "Peters Engineering");

                    SoapSerializationEnvelope Envelope = new SoapSerializationEnvelope(
                            SoapEnvelope.VER12); 
                    Envelope.dotNet=true;
                    Envelope.setOutputSoapObject(Request);


                    HttpTransportSE ht = new HttpTransportSE(url);
                    ht.debug = true;
                    ht.call(SOAP_ACTION, Envelope);

                    SoapObject response = (SoapObject) Envelope.getResponse();
                    final String SessionID = response.getProperty("SessionID").toString();


                runOnUiThread(new Runnable() {

                    public void run() {

                        TextView tv = (TextView) findViewById(R.id.textView1);
                        tv.setText(SessionID);

                    }
                });

                } catch (Exception e) {

                    e.printStackTrace();

                }   

            }


    };
    loginThread.start();
}

Here the part of the wsdl file which i want to call:

<wsdl:definitions name="DWService" targetNamespace="http://tempuri.org/">
 <wsdl:types>
  <xsd:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
   <xsd:element name="Login">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element minOccurs="0" name="userName" nillable="true" type="xsd:string"/> 
      <xsd:element minOccurs="0" name="password" nillable="true" type="xsd:string"/>
      <xsd:element minOccurs="0" name="organization" nillable="true" type="xsd:string"/> 
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>

I don´t have much expierience with Ksoap and Web-Services so i hope someone could help me solving this problem :)

greetings.

EDIT

i tryed using ?svc instead -> same errors :(

EDIT

Here the Header of the WSDL file maybe my Namespace is false

    <?xml version="1.0" encoding="UTF-8"?>
    -<wsdl:definitions xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:tns="http://tempuri.org/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
targetNamespace="http://tempuri.org/" name="DWService">
-<wsdl:types>-
<xsd:schema targetNamespace="http://tempuri.org/" elementFormDefault="qualified">-
<xsd:element name="Login">-
<xsd:complexType>-
<xsd:sequence>
<xsd:element name="userName" type="xsd:string" nillable="true" minOccurs="0"/>
<xsd:element name="password" type="xsd:string" nillable="true" minOccurs="0"/>
<xsd:element name="organization" type="xsd:string" nillable="true" minOccurs="0"/></xsd:sequence>
</xsd:complexType>
</xsd:element>
-<xsd:element name="LoginResponse">
-<xsd:complexType>-
<xsd:sequence>
<xsd:element name="LoginResult" type="q1:ClientServiceSession" nillable="true" minOccurs="0" 
xmlns:q1="http://schemas.datacontract.org/2004/07/DocuWare.WebServices.GAPIFunctionality.DataContracts"/>
</xsd:sequence></xsd:complexType></xsd:element>

And the Soap Part:

-<wsdl:binding name="BasicHttpBinding_IDWService" type="tns:IDWService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
-<wsdl:operation name="Login"><soap:operation style="document" soapAction="http://tempuri.org/IDWService/Login"/>
-<wsdl:input><soap:body use="literal"/></wsdl:input>
-<wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation>
-<wsdl:operation name="Logoff"><soap:operation style="document" soapAction="http://tempuri.org/IDWService/Logoff"/>
-<wsdl:input><soap:body use="literal"/></wsdl:input>
-<wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation>

-<wsdl:service name="DWService">
-<wsdl:port name="BasicHttpBinding_IDWService" binding="tns:BasicHttpBinding_IDWService"><soap:address location="http://localhost:9007/DWService"/></wsdl:port></wsdl:service>

Hope you can help me ;)

Annalisaannalise answered 16/11, 2012 at 8:4 Comment(3)
can you share the full log please ?Doldrums
please give correct url of wsdlEllynellynn
@Kirit please check question here #17987576Bove
I
2

Use Fiddler to track the traffic. Probably the server/service is returning Content-Length: 0 This could be anything, in my case it was Content-type mismatch sent from the client app and expected content-type on the server side. Since the exception clearly indicates that the ByteArrayInputStream received content of length <= 0 from the service.

I hope this will make you investigate more.

Cheers,

Izabel answered 21/11, 2012 at 0:47 Comment(0)
P
1

Have you checked debugging after this line?

SoapObject response = (SoapObject) Envelope.getResponse();

If you have returned properties by webservice?. Maybe no data it's returned

Use

int arraySize = response.getPropertyCount();

And check the length to know if you are receiving data

I think the argumentException can be produced because you are trying to access the property without checking it here:

final String SessionID = response.getProperty("SessionID").toString();

Test the propertyCount and tell us.

EDIT:

Test this please:

Change the SoapEnvelope from VER12 to VER11

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

Change the webService URL from wdsl to this type (svc):

 String URL = "http://host:8080/HelloWCF/Service1.svc";
Pacifistic answered 16/11, 2012 at 9:41 Comment(5)
The program crashes at ht.call... si i dont get to the responseAnnalisaannalise
Ah ok, thanks for adding some info. Is it an ASMX webservice?Pacifistic
I dont know but i will get this info soonAnnalisaannalise
Ver11 causes serilization error tryed it already... i will try this with svc and will write back as soon as i canAnnalisaannalise
Added new Infos from WSDL file i think my Soap Envelope object has some bugs please check the WSDL file and tell me if i use false namespaces if you wand access to the full WSDL file please write me an email at [email protected] then i will send you the URL.Annalisaannalise
T
1

Use like this:

BasicHttpbinding:

                SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
                Request.addProperty("userName", "demo");
                Request.addProperty("password", "demo1234");
                Request.addProperty("organization", "Peters Engineering");

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

                HttpTransportSE ht = new HttpTransportSE(URL);

               try {
                    ht.call(SOAP_ACTION, envelope);  
            final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

i have made some changes in your code.

1)

SoapSerializationEnvelope Envelope = new SoapSerializationEnvelope( SoapEnvelope.VER12);

change into

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

2) i have removed this part from your code.

ht.debug = true;

3)

SoapObject response = (SoapObject) Envelope.getResponse();

change into

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

make sure have you added internet permission in your manifest

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

if you didnt get the output by using this the problem might be your wsdl

For more Reference Hope this will help you.


PS.

WsHttpBinding:

     Element e = new Element();
    e.setName("To");
    e.setNamespace("http://www.w3.org/2005/08/addressing");
    e.addChild(Node.TEXT,
            "your URL HERE");


    Element e1 = new Element();
    e1.setName("Action");
    e1.setNamespace("http://www.w3.org/2005/08/addressing");
    e1.addChild(Node.TEXT,
            "http://tempuri.org/IService1/HelloTest");

request.addProperty("Celsius", "32");    

// use VER12 instead of VER11
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

envelope.dotNet=true;

// add HederOut to envelope
envelope.headerOut = new Element[] { e, e1 };

envelope.setOutputSoapObject(request);

Reference.

Tetany answered 2/8, 2013 at 6:26 Comment(2)
thanks for your reply please check my question here #17987576Bove
@Tarsem yes sure before that #13599513 read thatTetany
C
-3

my opt: 1.use the newest 3.1.0 ksoap2 jar:http://code.google.com/p/ksoap2-android/wiki/HowToUse?tm=2 2.changed v12 to v11

Childhood answered 14/11, 2013 at 4:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.