2
我試圖從方法Querypage
獲得響應。請求的例子可以發現here和「文檔」即可找到herekSoap2意外類型(在java.io InputStreamReader @ 414fae00中位置:END_DOCUMENT null @ 1:1)
的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 [email protected]:1 in java.io [email protected])
。
這是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>
您是否找到了解決方案?它適用於> 4.0但不在2.3 .. – feco 2012-07-15 20:14:16
嗯,我試過4.0.3,但我只收到一個空值。你是否得到了與上面相同的代碼的正確答案? – 2012-07-15 23:50:54
我使用了舊版本,它的工作原理是http://code.google.com/p/koslan/downloads/detail?name=ksoap2-j2se-full-2.1.2.jar&can=2&q= – feco 2012-07-16 00:58:29