gpt4 book ai didi

android - ksoap2 : java. lang.IllegalArgumentException : size <= 0 while making a http. 调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:23 24 4
gpt4 key购买 nike

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

我的问题是当我调用 soap 请求时出现异常:

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 文件头可能是我的命名空间是假的

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

希望你能帮助我;)

最佳答案

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

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

干杯,

关于android - ksoap2 : java. lang.IllegalArgumentException : size <= 0 while making a http. 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com