我希望在使用Android的特定网络之后连接到数据服务。服务。 Svc和https。
编码并获得以下错误。
我会等你的回答。
MainActivity.java
public class MainActivity extends Activity {
//I'm not sure this is it true. METHOD_NAME, NAMESPACE, URL, SOAP_ACTION
static final String METHOD_NAME = "GetTableUpdateVersionByTableName";
static final String NAMESPACE = "http://schemas.datacontract.org/2004/07/SecureFlight.Core.Domain.Synchronization";
static final String URL = "https://app.xxx.com/IntSecureFlight/SFInternal.svc";
static final String SOAP_ACTION = "http://tempuri.org/IOperationSvc/GetTableUpdateVersionByTableName";
TextView sonuc;
EditText tableName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sonuc = (TextView) findViewById(R.id.textView1);
tableName = (EditText) findViewById(R.id.editText1);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), tableName.getText(),Toast.LENGTH_LONG).show();
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("tableName", tableName.getText().toString());
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
try {
HttpTransportSE aht = new HttpTransportSE(URL);
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject result = (SoapObject) soapEnvelope.bodyIn;
if (result != null) {
sonuc.setText(result.getProperty(0).toString());
}
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Not Connections"+e.toString(),
Toast.LENGTH_LONG).show();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
错误消息
java.net.SocketTimeoutException: Read timed out
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeread(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.access$200(OpenSSLSocketImpl.java:55)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:532)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readln(HttpURLConnectionImpl.java:1279)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readServerResponse(HttpURLConnectionImpl.java:1351)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1644)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:117)
at org.ksoap2.transport.ServiceConnectionSE.getResponseCode(ServiceConnectionSE.java:103)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:193)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
at com.example.soapsdeneme.MainActivity$1.onClick(MainActivity.java:62)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
错误的原因是什么?
...谢谢
答案 0 :(得分:1)
完整的代码是
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sonuc = (TextView) findViewById(R.id.textView1);
tableName = (EditText) findViewById(R.id.editText1);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), tableName.getText(),Toast.LENGTH_LONG).show();
new AsyncTask<String, String, String>() {
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("tableName", tableName.getText().toString());
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
try {
HttpsTransportSE transportSE = new HttpsTransportSE(DOMAIN,443,"/IntSecureFlight/SFInternal.svc",1000);
transportSE.call(SOAP_ACTION, soapEnvelope);
Object result = soapEnvelope.getResponse();
if(result instanceof SoapFault12){
SoapFault12 soapResult = (SoapFault12) result;
message=soapResult.getLocalizedMessage();
}else if(result instanceof SoapObject){
SoapObject soapResult = (SoapObject) result;
message=soapResult.getProperty(0).toString();
}
} catch (SoapFault12 e) {
message = e.getMessage();
} catch (XmlPullParserException e) {
message = e.getMessage();
} catch (Exception e) {
message = e.getMessage();
}
return message;
}
@Override
protected void onPostExecute(String result) {
sonuc.setText(message);
super.onPostExecute(result);
}
}.execute();
}
});
}