开发者

Android call Web Service returns "error"

开发者 https://www.devze.com 2023-03-05 17:16 出处:网络
I called Web Service from Android: .java file: public class FirstScreen extends Activity { private static final String NAMESPACE = \"http://tempuri.org\";

I called Web Service from Android:

.java file:

public class FirstScreen extends Activity {


        private static final String NAMESPACE = "http://tempuri.org";
        private static final String URL = "http://w3schools.com/webservices/tempconvert.asmx";  
        private static final String SOAP_ACTION = "http://tempuri.org/FahrenheitToCelsius";
        private static final String METHOD_NAME = "FahrenheitToCelsius";

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById
                            (R.id.autoCompleteTextView1);       

            SoapObject r开发者_StackOverflow中文版equest = new SoapObject(NAMESPACE, METHOD_NAME); 
            request.addProperty("Fahrenheit", "89");

            SoapSerializationEnvelope envelope = 
                new SoapSerializationEnvelope(SoapEnvelope.VER11); 

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);           
                ACTV.setHint("Received :" + envelope.getResponse());
            } 
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mobitour.mytest"
      android:versionCode="1"
      android:versionName="1.0">    
   <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FirstScreen"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
     </application>    
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>     
    <uses-sdk android:minSdkVersion="8" />  
</manifest>

I followed this http://www.vimeo.com/9633556 when was writing application. However I have one problem: I receive a word "Error" instead of required string, I see "Received :Error" on my screen. I can't understand where's mistake!Do you?


I resolved

Very easy, it needs

envelope. dotNet = true;

before

envelope.setOutputSoapObject(request);
0

精彩评论

暂无评论...
验证码 换一张
取 消