调用 axis2 webservices 问题?
我在调用webservices 服务时报以下错误:12-06 14:49:09.381: W/System.err(10491): java.net.SocketException: socket failed: EACCES (Permission denied)
12-06 14:49:09.381: W/System.err(10491): at libcore.io.IoBridge.socket(IoBridge.java:583)
12-06 14:49:09.381: W/System.err(10491): at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
12-06 14:49:09.381: W/System.err(10491): at java.net.Socket.checkOpenAndCreate(Socket.java:663)
12-06 14:49:09.381: W/System.err(10491): at java.net.Socket.connect(Socket.java:807)
12-06 14:49:09.381: W/System.err(10491): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
12-06 14:49:09.381: W/System.err(10491): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
12-06 14:49:09.381: W/System.err(10491): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
12-06 14:49:09.381: W/System.err(10491): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
12-06 14:49:09.386: W/System.err(10491): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
12-06 14:49:09.386: W/System.err(10491): at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126)
12-06 14:49:09.386: W/System.err(10491): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:179)
12-06 14:49:09.386: W/System.err(10491): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
12-06 14:49:09.386: W/System.err(10491): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
12-06 14:49:09.386: W/System.err(10491): at com.example.wstest2.MainActivity$2.run(MainActivity.java:79)
12-06 14:49:09.386: W/System.err(10491): Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
12-06 14:49:09.386: W/System.err(10491): at libcore.io.Posix.socket(Native Method)
12-06 14:49:09.386: W/System.err(10491): at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
12-06 14:49:09.386: W/System.err(10491): at libcore.io.IoBridge.socket(IoBridge.java:568)
12-06 14:49:09.386: W/System.err(10491): ... 19 more
调用代码如下:
package com.example.wstest2;--------------------编程问答-------------------- 声明权限没有? --------------------编程问答--------------------
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String NAME_SPACE = "http://Hi";//http://ws.apache.org/axis2
private static final String WDSL_LINK = "http://203.171.229.187:8080/axis2/services/sayHello?wsdl";
private static final String METHOD_NAME = "sayHello";
private Button call_soap;
private TextView textView;
private String resultStr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.initUI();
this.call_soap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callWebService();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void initUI() {
call_soap = (Button) this.findViewById(R.id.button1);
textView = (TextView) this.findViewById(R.id.textView1);
}
private void callWebService() {
Thread thr = new Thread() {
public void run() {
try {
String name = "ssss";
//Soap Object 是 SoapSerializationEnvelope的重要组成部分
SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME);
request.addProperty("user", name);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(WDSL_LINK);
ht.call("", envelope);
String ret = String.valueOf(envelope.getResponse());
Log.d("resultStr = ", ret);
setResultStr(ret);
} catch (SoapFault e) {
e.printStackTrace();
Log.v("random",e.getMessage());
} catch (IOException e) {
e.printStackTrace();
Log.v("random",e.getMessage());
} catch (XmlPullParserException e) {
e.printStackTrace();
Log.v("random",e.getMessage());
}
}
};
thr.start();
textView.setText(resultStr);
}
public String getResultStr() {
return resultStr;
}
public void setResultStr(String resultStr) {
this.resultStr = resultStr;
}
}
在哪里声明权限啊~ --------------------编程问答-------------------- androidmanifest.xml:
<uses-permission android:name="android.permission.INTERNET"/> --------------------编程问答--------------------
谢谢~ 加上可以了~ 为什么 我clean后就会把<uses-permission <uses-permission android:name="android.permission.INTERNET"/>就丢失了呢? --------------------编程问答-------------------- clean应该不会自动清这个 --------------------编程问答-------------------- 在android客户端调用axis2 webservices
真想说你的程序是个奇葩,
我在服务端调用其它服务器的axis2,至少需要20个jar包,
android访问服务器,一般用http协议的url就可以了,不知道你的需求为什么会这么整
补充:移动开发 , Android