I am consuming tempconvert web services but it does not give any result just show blank screen.
Does that mean my app does not access the web services, or i have to some setting so it will connect to URL, i am using ksoap2 2.6.5 .
this is my code
package com.example.webservice2;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class WebService extends Activity {
private final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private final String METHOD_NAME = "CelsiusToFahrenheit";
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.tv);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("celsius", "32");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
tv.setText("status:" + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
i am using web service from this url
http://www.w3schools.com/webservices/tempconvert.asmx
Use AsyncTask like below, this worked for me, if you face any problems let me know
public class SyncroniseRecords extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
dialog.setMessage("Please wait...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
// Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
}
@Override
protected void onPostExecute(Void result)
{
dialog.cancel();
}
@Override
protected Void doInBackground(Void... params) {
/** Your Operation */
return null;
}
}
This will launch the Activity without any Black Screen. Using onPreExecute you can display the Progressbar.Once the process gets completed you can cancel it in OnPostExecute().
Hope it helps
有时您在代理网络上并且没有设置代理设置而不是发生此检查表明您不在代理网络上。
我希望你已经获得了互联网的许可,如果不是请按照下面的代码
<manifest xlmns:android...> ... <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.