android - 适用于 Android 的 C++ Builder WSDL 客户端

标签 android c++ delphi wsdl c++builder

我遇到了一个令人困惑的问题。我正在尝试创建一个使用 WSDL 的 Web cleint。 我正在使用 C++ RAD Studio 10 Seattle,但同样的问题发生在 RAD Studio XE8(旧版本)中。

1.我创建了一个多设备应用程序,添加了一个编辑组件和一个按钮。

2.我通过将 WSDL 文件的位置更改为“http://www.w3schools.com/webservices/tempconvert.asmx?WSDL”并将所有其他设置保留为默认值来创建一个 WSDL 导入器。

3.在按钮的 ButtonClick 事件上我写了两行代码:

 _di_TempConvertSoap Converter = GetTempConvertSoap(true,    
 "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL");

 Edit1->Text = Converter->CelsiusToFahrenheit("32");

所以在这三个步骤之后我有一个单元,它是带有表单和按钮事件的主要单元。以及 WSDL Importer 生成的一个文件“tempconvert.cpp”。它实际上只是将 WSDL 代码转换为 C++ 代码并定义与服务器通信的方法。在我的例子中,我有两种方法:FahrenheitToCelsius()CelsiusToFahrenheit(),在示例中我使用了 CelsiusToFahrenheit()

我将它编译到 32 位 Windows 平台,运行它,当我单击按钮时,结果“89.6”出现在编辑组件的文本中。所以这是按预期工作的。

但是当我将目标平台更改为“Android”并使用我的手机“Samsung GT-I8262”和 Android 4.1.2 运行该项目时,它只是停止并退出。我调试了这个问题,它在 RegTypes() 方法的 "tempconvert.cpp" 中的第一个命令处停止。

// ************************************************************************ 
//
// This routine registers the interfaces and types exposed by the WebService.
// ************************************************************************ //
static void RegTypes()
{
  /* TempConvertSoap */
  InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-8");
  InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/%operationName%");
  InvRegistry()->RegisterInvokeOptions(__delphirtti(TempConvertSoap), ioDocument);
  /* TempConvertSoap.FahrenheitToCelsius */
  InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "FahrenheitToCelsius", "",
                                    "[ReturnName='FahrenheitToCelsiusResult']", IS_OPTN);
  /* TempConvertSoap.CelsiusToFahrenheit */
  InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "CelsiusToFahrenheit", "",
                                    "[ReturnName='CelsiusToFahrenheitResult']", IS_OPTN);
  /* TempConvertHttpPost */
  InvRegistry()->RegisterInterface(__delphirtti(TempConvertHttpPost), L"http://www.w3schools.com/webservices/", L"utf-8");
  InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertHttpPost), L"");
}
#pragma startup RegTypes 32

有人知道为什么会发生这种情况吗?我试过另外两部三星手机,但没有用。关闭程序的错误是“Segmentation fault(11)”,更准确地说它停止在“System.pas”文件中的以下代码行:

u_strFromUTF8(PUChar(Dest), MaxDestChars, DestLen, MarshaledAString(Source), SourceBytes, ErrorConv);

以下是我找到的有关该函数的一些信息:

  1. u_strFromUTF8 - 将 UTF-8 字符串转换为 UTF-16 的函数。
  2. UCHAR 是一个字节(在 Delphi 中),所以 PUCHAR 是一个指向字节的指针。

我不知道这个函数可能会出什么问题,它显然只转换一个字符串。

所以我的问题是为什么该项目在 Windows 32 位版本上运行,但在 Android 上却抛出段错误(11)?

我希望我能找到解决这个问题的办法。我会继续寻找。

谢谢,

兹德拉夫科·多涅夫 :)

更新:

我拆线了:

InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-16");

得到:

  TInvokableClassRegistry *Class = InvRegistry();
  TTypeInfo *Info = __delphirtti(TempConvertSoap);
  UnicodeString Namespace = "http://www.w3schools.com/webservices/";
  UnicodeString WSDLEncoding = "utf-8";

  Class->RegisterInterface(Info, Namespace, WSDLEncoding);

而且我看到问题是在调用InvRegistry()函数的时候出现的,但是我还没有找到问题,因为我无法访问该函数的源代码。

最佳答案

我找到了解决方案。

我删除了那行

#pragma startup RegTypes 32

并在我创建表单时自行调用了方法 RegTypes(),它起作用了。

关于android - 适用于 Android 的 C++ Builder WSDL 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32844855/

相关文章:

multithreading - Delphi 上的线程上下文

windows - 一段时间后 TToolbar 停止显示按钮标题

c++ - 模板不在范围内

c++ - 套接字编程。 connect(...) api 问题

c++ - 在 64 位 Delphi 中加载 64 位 com DLL 时的枚举问题

android admob 未显示 - 屏幕尺寸太小

android - Andengine如何制作粒子效果?

android - 使用 0dp 布局宽度和重量给 child 充气(以编程方式)

java - 这是什么异常?

c++ - 创建简单链表时无法访问内存