android 不能调用cxf服务
建了一个CXF服务,可以在tomcat7上跑.但android不能调用。代码如下:IcxfWB .java
import javax.jws.WebService;
import javax.jws.WebParam;
import javax.jws.WebMethod;
@WebService
public inte易做图ce IcxfWB {
@WebMethod
String sayHello(@WebParam(name="name") String name);
}
================================
CxfWBImpl.java
public class CxfWBImpl implements IcxfWB{
public String sayHello(String name) {
return "Hello "+name;
}
}
============================================
andorid代码如下:MainActivity.java
package com.example.testandr;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.EditText;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
//http://localhost:8080/cxftest/sayHello?wsdl
public class MainActivity extends Activity {
final static String SERVICE_NS = "http://unknown.namespace/";
final static String SERVICE_URL = "http://10.0.0.15:8080/cxftest/sayHello";
private EditText txt1;
private EditText txt2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt1 = (EditText) findViewById(R.id.editText1);
txt2 = (EditText) findViewById(R.id.editText2);
//调用的方法
String methodName = "sayHello";
//创建httpTransportSE传输对象
HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
ht.debug = true;
//使用soap1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//实例化SoapObject对象
SoapObject request = new SoapObject(SERVICE_NS, methodName);
/**
* 设置参数,参数名不一定需要跟调用的服务器端的参数名相同,只需要对应的顺序相同即可
* */
request.addProperty("name", "1006010054");
//将SoapObject对象设置为SoapSerializationEnvelope对象的传出SOAP消息
envelope.dotNet=false;
envelope.bodyOut = request;
try{
//调用webService
ht.call(null, envelope);
//txt1.setText("看看"+envelope.getResponse());
if(envelope.getResponse() != null){
txt2.setText("有返回");
SoapObject result = (SoapObject) envelope.bodyIn;
String name = result.getProperty(0).toString();
System.out.println(name);
txt1.setText("返回值 = "+name);
}else{
txt2.setText("无返回");
}
}catch (Exception e) {
e.printStackTrace();
System.out.println( e.getMessage().toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}
--------------------编程问答-------------------- AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testandr"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <intent-filter>
<data
android:host="Androidtest"
android:scheme="aone" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="te" /> -->
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
===========================================================
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout> --------------------编程问答-------------------- <data
android:host="Androidtest"
android:scheme="aone" /> 隐去 --------------------编程问答-------------------- 已经注释了
补充:移动开发 , Android