public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main);
SoapObject request = new SoapObject("http://tempuri.org/", "HelloWorld");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport ht = new AndroidHttpTransport("http://192.168.1.101/Service/Service1.asmx");
try {
//这一步报错java.net.SocketException: Permission denied
ht.call("http://tempuri.org/HelloWorld",envelope);
SoapObject soapObject = (SoapObject) envelope.getResponse();
TextView tvResult = (TextView)findViewById(R.string.hello);
tvResult.setText(soapObject.getProperty(0)+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}对java.net.SocketException: Permission denied
网上说加权限<uses-permission android:name="android.permission.INTERNET" /> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.web"
android:versionCode="1"
android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityWeb"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
最后还是报那个错!有专家分析下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.web"
android:versionCode="1"
android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityWeb"
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" />
</manifest>
这样试下,权限语句放在application外面。
但现在又报下面错误,帮我看看程序代码 正确否public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main);
SoapObject request = new SoapObject("http://tempuri.org/", "HelloWorld");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport ht = new AndroidHttpTransport("http://192.168.1.101/Service/Service1.asmx");
try {
ht.call("http://tempuri.org/HelloWorld",envelope);
//报java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive
SoapObject soapObject = (SoapObject) envelope.getResponse();
TextView tvResult = (TextView)findViewById(R.string.hello);
tvResult.setText(soapObject.getProperty(0)+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
引用不对。、
把引用路径全部写上可过、
如:
org.ksoap2.serialization.SoapObject soa=new org.ksoap2.serialization.SoapObject("http://tempuri.org/", "HelloWorld");
检查引用ksoap包时是否有错误!
就通过了,虽然成功了,不知道为什么