我想從SAP SOAP Web服務獲取響應,但我得到一個異常。來自SOAP webservices的GetResponse在Android中
我用下面的代碼:
package com.veee.pack;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportBasicAuth;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Element;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WeservicesExampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//getting these values from wsdl file
//username and password appended as URL Parameters
final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
final String URL = "http://*********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user******&sap-password=************";
final String METHOD_NAME = "Z_GET_CUST_GEN";
final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
SoapObject request =new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Input", "1460");
request.addProperty("Langu", "d");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
HttpTransportSE httptransport=new HttpTransportSE(URL);
httptransport.debug = true;
try {
//calling the services
httptransport.call(SOAP_ACTION, envelope);
Object result = (Object) envelope.getResponse();
//getting the Response Here.
System.out.println("Result" + result.toString());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
當我調試它終止應用程序在
httptransport.call(SOAP_ACTION, envelope);
我在Android的它工作正常使用ksoap2跑了一些例子。我得到了我的logcat以下異常:
04-24 12:19:17.935: WARN/System.err(1569): java.net.SocketTimeoutException
04-24 12:19:17.935: WARN/System.err(1569): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)
請給予任何建議來解決這個問題,或發送我怎樣才能使請求並接收通過XML在Android上的響應。
預先感謝.....
'java.net.SocketTimeoutException'似乎暗示您正在嘗試與未打開的服務進行通信。假設你的'URL'地址指向一個僅在你的內部網絡上公開的SAP服務 - 你如何連接到它,僅限WiFi?你可以使用Wireshark(或類似的)來檢查你是否連接到它? – Jens 2012-04-24 09:24:06
感謝您回覆我使用有線網絡,但soapui親其工作良好如何使其更快在Android模擬器 – 2012-04-24 09:47:12
是否有任何需要的設置? – 2012-04-24 09:47:40