gpt4 book ai didi

java - 无法从android中的tomcat服务器访问我的WSDL文件

转载 作者:行者123 更新时间:2023-11-28 23:46:33 30 4
gpt4 key购买 nike

我必须开发一个 android 应用程序。该应用程序执行从 mysql 数据库检索数据并显示在 android 模拟器和 android 设备上。

首先,我必须在本地主机上设置 tomcat 服务器,并在本地主机上运行这些 wsdl 文件,这意味着获取的检索数据已成功显示在模拟器和安卓设备上。

此外,我还必须在远程设置 tomcat 服务器。我已经上传了我的 war 文件并获取了 wsdl 文件。现在我必须输入这些 wsdl URL,这意味着我的模拟器和 android 设备上都会出现空白屏幕。

我的控制台窗口显示以下错误:

11-19 19:43:26.331: W/System.err(6323): java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
11-19 19:43:26.341: W/System.err(6323): at com.retailer.client.RetailerActivity.onCreate(RetailerActivity.java:36)
11-19 19:43:26.341: W/System.err(6323): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-19 19:43:26.341: W/System.err(6323): at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 19:43:26.341: W/System.err(6323): at android.os.Looper.loop(Looper.java:123)
11-19 19:43:26.341: W/System.err(6323): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-19 19:43:26.341: W/System.err(6323): at java.lang.reflect.Method.invokeNative(Native Method)
11-19 19:43:26.341: W/System.err(6323): at java.lang.reflect.Method.invoke(Method.java:521)
11-19 19:43:26.341: W/System.err(6323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-19 19:43:26.341: W/System.err(6323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-19 19:43:26.341: W/System.err(6323): at dalvik.system.NativeStart.main(Native Method)

我该如何解决这个错误。请帮助我。

这是我的代码:

    public class RetailerActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.testprops.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://ws.testprops.com";
//private static final String URL = "http://10.0.0.133:8089/TestPrompts/services/Fetch?wsdl";
private static final String URL = "http://87.76.29.180:8080/TestPrompts/services/Fetch?wsdl";
/*
private static final String SOAP_ACTION = "http://xcart.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://10.0.0.133:8089/XcartLogin/services/Fetch?wsdl";*/

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} catch (Exception e) {
//Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
e.printStackTrace();
}
}
}

这是我的第 36 行:

 SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

我必须把这个 url

private static final String URL = "10.0.0.133:8089/TestPrompts/services/Fetch?wsdl";

表示正在检索数据。此 wsdl 文件在位于本地主机的 tomcat 服务器上运行

但我必须将这些 url 表示为

private static final String URL = "87.76.29.180:8080/TestPrompts/services/Fetch?wsdl";

这次只是出现以上错误。此 wsdl 文件在 远程 tomcat 服务器 上运行。

最佳答案

我相信您得到的不是原始类型。试试这个:

SoapObject response = (SoapObject)envelope.getResponse();

参见:Trying to build a correct SOAP Request

关于java - 无法从android中的tomcat服务器访问我的WSDL文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13466525/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com