2

我正在尝试从方法中获得响应Querypage可以在此处找到请求示例,并且可以在此处找到“文档”

API 可以在这里找到(勾选底部的框并单击按钮以查看 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).

这是请求转储:

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

1 回答 1

0

Thanx Feco, as you said using and old version of the library do the job! For those that get networkonmainthreadexception with this old library only append this to your code:

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

Thats All! All is working well now! Juan Chipoco

于 2012-07-22T15:19:36.163 回答