kSoap2意外类型(位置:在java.io InputStreamReader @ 414fae00中END_DOCUMENT null @ 1:1)

时间:2012-07-15 13:33:02

标签: android xml soap ksoap2 android-ksoap2

我正在尝试从方法Querypage获得回复。可以找到here请求的示例,并且可以找到“文档”here

可以找到API here(勾选底部的框,然后点击按钮查看api页面,它基本上只是他们确保您已阅读规则等的一种方式。 )。

public class KSoap2Activity extends Activity {
    private static final String SOAP_ACTION =  "http://www.etis.fskab.se/v1.0/ETISws/Querypage";
    private static final String METHOD_NAME = "Querypage";
    private static final String NAMESPACE = "http://www.etis.fskab.se/v1.0/ETISws";
    private static final String URL = "http://www.labs.skanetrafiken.se/v2.2/querypage.asp";

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

    TextView tv = (TextView) findViewById(R.id.text);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("inpPointFr", "lund");
    request.addProperty("inpPointTo", "ystad");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE ht = new HttpTransportSE(URL);
    ht.debug = true;

    try {
        ht.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        tv.setText("Message :" + response.toString());
    } catch (Exception e) {
        e.printStackTrace();
        tv.setText(e.getMessage()+ ht.requestDump);
    }
}

}

我收到一个例外:unexpected type(position:END_DOCUMENT null@1:1 in java.io InputStreamReader@414fae00)

这是requestDump:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header />
    <v:Body>
        <Querypage xmlns="http://www.etis.fskab.se/v1.0/ETISws" id="o0" c:root="1">                                                   
            <inpPointFr i:type="d:string">lund</inpPointFr>
            <inpPointTo i:type="d:string">ystad</inpPointTo>
        </Querypage>
    </v:Body>
</v:Envelope>

1 个答案:

答案 0 :(得分:0)

Thanx Feco,正如你所说的使用和旧版本的库做的工作! 对于那些使用这个旧库获取networkonmainthreadexception的人,只需将其附加到您的代码中:

    //Codigo para evitar el networkonmainthreadexception 
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()   
    .detectDiskReads()   
    .detectDiskWrites()   
    .detectNetwork()   // or .detectAll() for all detectable problems   
    .penaltyLog()   
    .build());   
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()   
    .detectLeakedSqlLiteObjects()   
    .detectLeakedClosableObjects()   
    .penaltyLog()   
    .penaltyDeath()   
    .build());  

多数民众赞成! 现在一切都很好! Juan Chipoco