gpt4 book ai didi

c - 如何使用 wsdl 2c 生成的 c 文件连接到 Web 服务

转载 作者:行者123 更新时间:2023-11-30 15:24:56 27 4
gpt4 key购买 nike

我使用 axis2c 从 wsdl 文件生成 c 文件。 (this is the WSDL file I used)现在我有这些文件列表:

adb_helloName.c
adb_helloNameResponse.c
axis2_extension_mapper.c
axis2_stub_HelloService.c
plus I have their header files. and a HelloServiceClient.vcproj file.

我在 Visual Studio 中创建了一个项目,现在我想知道如何连接到 Web 服务并获取返回值。 (在本例中,我有一个 hello world wsdl 文件,它获取名称并传递“Hello + (thatName)”)

提前谢谢您。

最佳答案

我已经找到解决办法了。我尝试使用自己的 wsdl 文件创建自己的服务器。

我在 JAVA 中创建了一个服务器,它获取 2 个数值并将它们加在一起:

public class Math {

public int addOperator(int num1, int num2){
return (num1+num2);
}
}

然后我在 Eclipse 中创建了 WSDL 文件。我从 WSDL 文件创建了 c 文件:

adb_addOperator.c

adb_addOperatorResponse.c

axis2_extension_mapper.c

axis2_stub_MathService.c

plus I have their header files.

MathServiceClient.vcproj file.

我在 Visual Studio 中导入了这个项目。然后我将此 math.c 文件添加到我的项目中:

#include "axis2_stub_MathService.h"

int main(
int argc,
char *argv)
{
axutil_env_t * env = NULL;
axis2_char_t * operation = NULL;
axis2_char_t * client_home = NULL;
axis2_char_t * endpoint_uri = NULL;
axis2_stub_t * stub = NULL;
adb_addOperatorResponse_t * add_res = NULL;
adb_addOperator_t * add_in = NULL;
int res_val = 0;
endpoint_uri = "http://localhost:8080/AddOperator/services/Math"; //this is the tomcatServer running the MathServer
env = axutil_env_create_all("alltest.log", AXIS2_LOG_LEVEL_TRACE);

/* Set up deploy folder. */
client_home = AXIS2_GETENV("AXIS2C_HOME");
if (!client_home)
client_home = "../../../deploy";
stub = axis2_stub_create_MathService(env, client_home, endpoint_uri);
add_in = adb_addOperator_create(env);
adb_addOperator_set_num1(add_in, env, 14); //initializing num1
adb_addOperator_set_num2(add_in, env, 33); //initializing num2
add_res = axis2_stub_op_MathService_addOperator(stub, env, add_in);
if (!add_res)

{
printf("Error: response NULL\n");
return -1;
}
res_val = adb_addOperatorResponse_get_addOperatorReturn(add_res, env);
printf("Add Result : %d ", res_val);

return 0;
}

编译了项目。然后我打开cmd并打开MathService.exe目录。然后我运行 MathService。它工作正常。

关于c - 如何使用 wsdl 2c 生成的 c 文件连接到 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149999/

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