android soap webservers 無法執行 報錯 ht.call(SOAP_ACTION, envelope);解決方案

來源:互聯網
上載者:User

標籤:

1.可能沒有加入網路存取權限,在Manifest裡面加入,<uses-permission android:name="android.permission.INTERNET"/>

2.版本問題,很可能的問題,因為在android高於9的會出錯,所以簡單粗暴的辦法就是,直接將版本資訊

<uses-sdk
android:minSdkVersion="?"
android:targetSdkVersion="?"

/>

刪除即可。

 

其他具體參考代碼如下:

 1 package com.example.soaptestforandroid; 2  3 import java.io.IOException; 4  5 import org.ksoap2.SoapEnvelope; 6 import org.ksoap2.serialization.SoapObject; 7 import org.ksoap2.serialization.SoapSerializationEnvelope; 8 import org.ksoap2.transport.HttpTransportSE; 9 import org.xmlpull.v1.XmlPullParserException;10 11 import android.os.*;12 import android.annotation.SuppressLint;13 import android.app.Activity;14 import android.util.Log;15 import android.view.Menu;16 import android.widget.*;17 18 public class MainActivity extends Activity19 {20 21     private static final String SERVICE_NAMESPACE = "http://services.jason.com/";22     private static final String SERVICE_URL = "http://172.16.1.164:8080/MyWebServer/UserInfoPort?wsdl";23     private EditText tv = null;24     25     26     27     @SuppressLint("NewApi")28     @Override29     protected void onCreate(Bundle savedInstanceState)30     {31         super.onCreate(savedInstanceState);32         setContentView(R.layout.activity_main);33         34         35         try {36         tv = (EditText) findViewById(R.id.hello);37         38         //如果本系統為4.0以上(Build.VERSION_CODES.ICE_CREAM_SANDWICH為android4.0)39         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {40             // 詳見StrictMode文檔41             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()42                     .detectDiskReads().detectDiskWrites().detectNetwork()43                     .penaltyLog().build());44             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()45                     .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()46                     .penaltyLog().penaltyDeath().build());47         }48 49         // 調用的方法50         String mathodName = "GetUserInfo";51         String SOAP_ACTION = SERVICE_NAMESPACE + mathodName;52         // 建立HttpTransportSE對象53             HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);54         55             ht.debug = true;56             // 使用soap協議建立Envelop對象57             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(58                     SoapEnvelope.VER10);59             // 執行個體化SoapObject對象60             SoapObject object = new SoapObject(SERVICE_NAMESPACE, mathodName);61             // 將SoapObject對象設定為SoapSerializationEnvelope對象的傳出SOAP訊息62             envelope.bodyOut = object;63             envelope.dotNet = true;64             envelope.setOutputSoapObject(object);65                 // 調用webService66                 ht.call(SOAP_ACTION, envelope);67                 System.out.println("envelope.getResponse()---"68                         + envelope.getResponse());69                 if (envelope.getResponse()!= null) {70             71                     SoapObject result = (SoapObject) envelope.bodyIn;72                     String name = result.getProperty(0).toString();73                     System.out.println(name);74                     tv.setText("傳回值為:" + name);75                     76                 } else {77                     tv.setText("無傳回值");78                 }79             } catch (Exception e) {80                 // TODO Auto-generated catch block81                 e.printStackTrace();82             } 83         84     }85 86     @Override87     public boolean onCreateOptionsMenu(Menu menu)88     {89         // Inflate the menu; this adds items to the action bar if it is present.90         getMenuInflater().inflate(R.menu.main, menu);91         return true;92     }93 94 }
View Code

 

android soap webservers 無法執行 報錯 ht.call(SOAP_ACTION, envelope);解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.