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

标签 c web-services wsdl client stub

我使用 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/

相关文章:

c# - SOAP Web服务: many servers, 一个接口(interface)

计算没有浮点运算或日志的对数表达式

c - 无法弄清楚为什么 printf 在标准输出上打印不同

C 删除字符串中的字符

web-services - 使用 JAX-WS,如何在一个 wsdl 中拥有多个端口?

php - 将 PHP SoapClient 类映射选项与包含同名元素和复杂类型的 WSDL 一起使用

c - 无论如何要知道变量是否已在 C 中初始化?

jquery - 将 Authorization header 附加到 Ajax 请求的正确方法是什么?

.net - Web 服务的依赖注入(inject)?

java - 在线 Java 线程转储分析器