gpt4 book ai didi

c++ - Axis2C 非官方 vs. Axis2C 员工

转载 作者:搜寻专家 更新时间:2023-10-31 01:07:57 29 4
gpt4 key购买 nike

我将要开发一个应用程序,该应用程序将使用一些基于 SOAP 的 Web 服务框架。我做了一些研究,我有点喜欢 Axis2C 框架,但在某些主题中,我发现原来的 Axis2C 实现存在内存泄漏问题,并且它的官方开发已经停止。

幸运的是,存在Axis2C 非官方分支和基于Axis2C 的Staff 框架。现在的问题是,这个 Axis2C 后代中哪个更好用或更容易使用?我知道,Staff 用 C++ 包装了 Axis2C,但我不介意纯 C。Staff 是否也修复了内存泄漏?

感谢您的任何建议。

最佳答案

我不能告诉您关于 Axis2/C 的工作已经停止,它仍在继续,但速度非常非常慢。如果你查看 trunk repo ,你可以看到今年只有 5 次提交...... Trunk 版本 1.7.0(未发布)有很多变化和新功能,但发布日期仍然未知。

原来的 Axis2/C-1.6.0 确实存在内存泄漏和已知问题,不适合生产。 Axis2/C-unofficial 基于原始的 Axis2/C-1.6.0 并修复了大部分关键问题并提供了其他有用的功能。但是非官方分支当然有和原来一样的API,你会花同样的时间来开发服务或客户端。 使用起来并没有更简单或更难。

如果我们谈论 WSF Staff,它旨在快速开发 WEB 服务和客户端。与 Axis2/C 相比,您只需编写几行代码即可启动您的服务或客户端工作。您不需要了解内部消息结构:您只使用简单(bool、int、string 等)或复杂(struct、typedef、std 容器...)类型(当然您可以使用低级别访问消息)。 Axis2/C 具有名为 ADB(Axis 数据绑定(bind))的类似功能,但它是通过 C 方式完成的,您需要编写额外的代码行才能访问请求和结果。

Please note ADB (and generated services) has memory leaks, and it's not fixed in unofficial branch.

为了比较哪个更容易使用 - ADB 或 Staff 我想举这个例子:

Note: you need to write the code between { and } by hand.

Axis2/C 在 Axis2/C 示例中实现不带 ADB 的计算器服务添加操作的方法(传统):

axiom_node_t *
axis2_calc_add(
const axutil_env_t * env,
axiom_node_t * node)
{
axiom_node_t *param1_node = NULL;
axiom_node_t *param1_text_node = NULL;
axis2_char_t *param1_str = NULL;
long int param1 = 0;
axiom_node_t *param2_node = NULL;
axiom_node_t *param2_text_node = NULL;
axis2_char_t *param2_str = NULL;
long int param2 = 0;

if (!node)
{
AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL,
AXIS2_FAILURE);
printf("Calculator client request ERROR: input parameter NULL\n");
return NULL;
}

/* iterating to the first child element skipping (empty) text elements */
for (param1_node = axiom_node_get_first_child(node, env);
param1_node && axiom_node_get_node_type(param1_node, env) != AXIOM_ELEMENT;
param1_node = axiom_node_get_next_sibling(param1_node, env));

if (!param1_node)
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}
param1_text_node = axiom_node_get_first_child(param1_node, env);
if (!param1_text_node)
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}
if (axiom_node_get_node_type(param1_text_node, env) == AXIOM_TEXT)
{
axiom_text_t *text =
(axiom_text_t *) axiom_node_get_data_element(param1_text_node, env);
if (text && axiom_text_get_value(text, env))
{
param1_str = (axis2_char_t *) axiom_text_get_value(text, env);
}
}
else
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}

/* iterating to the second child element skipping (empty) text elements */
for (param2_node = axiom_node_get_next_sibling(param1_node, env);
param2_node && axiom_node_get_node_type(param2_node, env) != AXIOM_ELEMENT;
param2_node = axiom_node_get_next_sibling(param2_node, env));
if (!param2_node)
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}
param2_text_node = axiom_node_get_first_child(param2_node, env);
if (!param2_text_node)
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}
if (axiom_node_get_node_type(param2_text_node, env) == AXIOM_TEXT)
{
axiom_text_t *text =
(axiom_text_t *) axiom_node_get_data_element(param2_text_node, env);
if (text && axiom_text_get_value(text, env))
{
param2_str = (axis2_char_t *) axiom_text_get_value(text, env);
}
}
else
{
AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid XML in request\n");
return NULL;
}

if (param1_str && param2_str)
{
long int result = 0;
axis2_char_t result_str[255];

axiom_element_t *ele1 = NULL;
axiom_node_t *node1 = NULL,
*node2 = NULL;
axiom_namespace_t *ns1 = NULL;
axiom_text_t *text1 = NULL;

param1 = strtol(param1_str, NULL, 10);
param2 = strtol(param2_str, NULL, 10);
result = param1 + param2;
sprintf(result_str, "%ld", result);

ns1 = axiom_namespace_create(env,
"http://axis2/test/namespace1", "ns1");
ele1 = axiom_element_create(env, NULL, "result", ns1, &node1);
text1 = axiom_text_create(env, node1, result_str, &node2);

return node1;
}

AXIS2_ERROR_SET(env->error,
AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST,
AXIS2_FAILURE);
printf("Calculator service ERROR: invalid parameters\n");
return NULL;
}

Axis2/C 代码生成示例中使用 ADB 实现计算器服务添加操作的方法:

    adb_addResponse_t * axis2_skel_Calculator_add(const axutil_env_t * env,
adb_add_t * add)
{
adb_addResponse_t * add_res = NULL;
int ret_val = 0;
int val1 = 0;
int val2 = 0;
val1 = adb_add_get_arg_0_0(add, env);
val2 = adb_add_get_arg_1_0(add, env);
ret_val = val1 + val2;
add_res = adb_addResponse_create(env);
adb_addResponse_set_addReturn(add_res, env, ret_val);
return add_res;
}

工作人员实现计算器服务添加操作的方式:

int CalculatorImpl::add(int param_1, int param_2)
{
return param_1 + param_2;
}

关于代码生成和编译过程,它将是:

对于 Axis2/C:

# generate service from WSDL
WSDL2C.sh -uri Calculator.wsdl -u -ss -sd
# implement src/axis2_skel_Calculator.c
# compile and install
cd src
# build
sh build.sh
# install
sudo mkdir $AXIS2C_HOME/services/calculator
sudo cp lib*.so ../resources/*.xml $AXIS2C_HOME/services/calculator

对于 WSF 员工:

# generate service from WSDL
staff_codegen -pwsdl -tcomponent_all Calculator.wsdl
# implement src/CalculatorImpl.cpp
# build and install
make && sudo -E make install

当然,您可以在 Axis2/C-unofficial 上使用 WSF Staff,以获得两者的所有好处。

关于c++ - Axis2C 非官方 vs. Axis2C 员工,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18624349/

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