【问题标题】:ksoap2 : java.lang.IllegalArgumentException: size <= 0 while making a http.callksoap2 : java.lang.IllegalArgumentException: size <= 0 while making a http.call
【发布时间】:2012-11-16 08:04:17
【问题描述】:

我想通过我的 Android 4.03 设备使用 Ksoap2 连接到基于 dot.net 的 Web 服务。

我的问题是当我调用肥皂请求时,我得到了这个异常:

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)

我正在使用的代码

    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();
}

这里是我要调用的 wsdl 文件部分:

<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>

我对 Ksoap 和 Web 服务没有太多经验,所以我希望有人可以帮助我解决这个问题 :)

问候。

编辑

我尝试使用 ?svc 代替 -> 相同的错误 :(

编辑

这里 WSDL 文件的 Header 可能我的命名空间是假的

    <?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>

还有肥皂部分:

-<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>

希望你能帮助我;)

【问题讨论】:

标签: android wsdl ksoap2 soap1.2


【解决方案1】:

使用Fiddler 跟踪流量。可能服务器/服务正在返回Content-Length: 0 这可能是任何东西,在我的情况下,它是从客户端应用程序发送的 Content-type 不匹配和服务器端的预期内容类型。由于异常清楚地表明ByteArrayInputStream 从服务接收到 的内容。

我希望这会让您进行更多调查。

干杯,

【讨论】:

    【解决方案2】:

    在这行之后你检查过调试吗?

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

    如果您已通过 web 服务返回属性?可能没有返回数据

    使用

    int arraySize = response.getPropertyCount();
    

    并检查长度以了解您是否正在接收数据

    我认为argumentException可以产生,因为你正在尝试 访问该属性而不在这里检查它:

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

    测试 propertyCount 并告诉我们。

    编辑:

    请测试一下:

    将 SoapEnvelope 从 VER12 更改为 VER11

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
    

    将 webService URL 从 wdsl 更改为这种类型 (svc):

     String URL = "http://host:8080/HelloWCF/Service1.svc";
    

    【讨论】:

    • 程序在 ht.call 处崩溃...我没有得到响应
    • 嗯,好的,感谢您添加一些信息。它是一个 ASMX 网络服务吗?
    • 我不知道,但我很快就会得到这个信息
    • Ver11 导致序列化错误已经尝试过了...我将尝试使用 svc 并尽快回信
    • 从 WSDL 文件中添加了新信息我认为我的 Soap Envelope 对象有一些错误请检查 WSDL 文件并告诉我如果你想访问完整的 WSDL 文件我是否使用了错误的命名空间请给我写一封电子邮件在 lukasjesenko@gmail.com 然后我会把 URL 发给你。
    【解决方案3】:

    这样使用:

    基本的Http绑定:

                    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();
    

    我已对您的代码进行了一些更改。

    1)

    SoapSerializationEnvelope 信封 = 新的 SoapSerializationEnvelope( SoapEnvelope.VER12);

    换成

    SoapSerializationEnvelope 信封 = 新 SoapSerializationEnvelope(SoapEnvelope.VER11);

    2) 我已从您的代码中删除了这部分。

    ht.debug = true;

    3)

    SoapObject 响应 = (SoapObject) Envelope.getResponse();

    改成

    SoapPrimitive 响应 = (SoapPrimitive)envelope.getResponse();

    确保您已在清单中添加互联网权限

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

    如果你没有通过使用这个得到输出,问题可能是你的 wsdl

    更多Reference 希望这会对你有所帮助。


    附言。

    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.

    【讨论】:

    【解决方案4】:

    我的选择: 1.使用最新的3.1.0 ksoap2 jar:http://code.google.com/p/ksoap2-android/wiki/HowToUse?tm=2 2.将v12改为v11

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-02
      • 2016-01-31
      • 2022-12-26
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多