【问题标题】:C++ Builder WSDL client for Android适用于 Android 的 C++ Builder WSDL 客户端
【发布时间】:2015-09-29 13:08:21
【问题描述】:

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

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

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

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

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

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

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

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

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

// ************************************************************************ 
//
// 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 上却抛出 Segmentation fault(11)?

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

谢谢,

Zdravko Donev :)

更新:

我拆线了:

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()函数时出现问题,但是由于无法访问该函数的源代码,我仍然没有发现问题。

【问题讨论】:

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


    【解决方案1】:

    我找到了解决办法。

    我删除了该行

    #pragma startup RegTypes 32
    

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

    【讨论】:

      猜你喜欢
      • 2013-02-21
      • 2014-08-06
      • 1970-01-01
      • 2010-12-01
      • 1970-01-01
      • 2017-09-04
      • 2019-01-10
      • 1970-01-01
      • 2020-04-06
      相关资源
      最近更新 更多