我使用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中创建了一个项目,现在我想知道如何连接到webservice并获取返回值。 (在这种情况下,我有一个hello world wsdl文件,它获取一个名称并传递" Hello +(thatName)")
提前谢谢你。
答案 0 :(得分:1)
我找到了解决方案。我尝试使用自己的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
加上我有他们的头文件。
MathServiceClient.vcproj文件。
我在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。 它运作正常。