Can't access tempconvert web services

青春壹個敷衍的年華 提交于 2019-12-25 02:59:37

问题


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

回答1:


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




回答2:


Sometime when you are on the proxy network and not set the proxy setting than this occured check that you are not on proxy network.




回答3:


I hope you have given permission for internet if not pls follow below code

<manifest xlmns:android...> ... <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest>



来源:https://stackoverflow.com/questions/11590719/cant-access-tempconvert-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!