vc 调用webservice
2016-05-23 14:39
267 查看
snoap下载地址
https://sourceforge.net/projects/gsoap2/?source=typ_redirect
新建vc工程并添加源文件
./snoap/bin/win32/soapcpp2.exe拷贝到工程目录
cmd 运行soapcpp2.exe 会生成一大堆文件
我们先在源文件中声明一个接口
int plus(int num_1, int num_2, int *sum);
编译再运行soapcpp2.exe
添加文件
stdsoap2.h
stdsoap2.cpp
这两个文件在下载包中
soapH.h
soapC.cpp
soapStub.h
soapServer.cpp
到工程目录
其中soapH.h和soapC.cpp是具体的实现,soapStub.h为代理的声明
编译出现了两个无法解析的外部符号
1>------ 已启动生成: 项目: ClipBoard, 配置: Debug Win32 ------
1>soapServer.obj : error LNK2019: 无法解析的外部符号 "int __cdecl plus(struct soap *,int,int,int *)" (?plus@@YAHPAUsoap@@HHPAH@Z),该符号在函数 "int __cdecl soap_serve_plus(struct soap *)" (?soap_serve_plus@@YAHPAUsoap@@@Z)
中被引用
1>stdsoap2.obj : error LNK2001: 无法解析的外部符号 _namespaces
1>D:\MyCode\SpasvoProc\Output\Debug\ClipBoard.exe : fatal error LNK1120: 2 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
第一个是因为只声明没有实现
将soapStub.h文件最后的函数放在另个文件中实现
SOAP_FMAC5 int SOAP_FMAC6 plus(struct soap*, int num_1, int num_2, int *sum)
{
*sum = num_1 + num_2;
printf("sum = %d", sum);
return SOAP_OK;
}
解决了一个问题
1>------ 已启动生成: 项目: ClipBoard, 配置: Debug Win32 ------
1> TestWebServer.cpp
1>stdsoap2.obj : error LNK2001: 无法解析的外部符号 _namespaces
1>D:\MyCode\SpasvoProc\Output\Debug\ClipBoard.exe : fatal error LNK1120: 1 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
百度一下
在工程中添加 WITH_NONAMESPACES宏//运行时会出错
#include "soap.nsmap"
编译通过
源文件中添加代码
运行之后浏览器输入http://localhost:8696/
显示
客户端新建一个工程项目,可以添加服务器生成的文件,也可以重新生成,
在客户端源文件中添加代码
运行结果
客户端:
服务器端:
在会遇到中文乱码的情况下,typename.dat加上xsd::string = std::wstring | wchar_t*
Couldn't find a matching Java operation for WSDD operation
webService 函数名小写
https://sourceforge.net/projects/gsoap2/?source=typ_redirect
新建vc工程并添加源文件
./snoap/bin/win32/soapcpp2.exe拷贝到工程目录
cmd 运行soapcpp2.exe 会生成一大堆文件
我们先在源文件中声明一个接口
int plus(int num_1, int num_2, int *sum);
编译再运行soapcpp2.exe
添加文件
stdsoap2.h
stdsoap2.cpp
这两个文件在下载包中
soapH.h
soapC.cpp
soapStub.h
soapServer.cpp
到工程目录
其中soapH.h和soapC.cpp是具体的实现,soapStub.h为代理的声明
编译出现了两个无法解析的外部符号
1>------ 已启动生成: 项目: ClipBoard, 配置: Debug Win32 ------
1>soapServer.obj : error LNK2019: 无法解析的外部符号 "int __cdecl plus(struct soap *,int,int,int *)" (?plus@@YAHPAUsoap@@HHPAH@Z),该符号在函数 "int __cdecl soap_serve_plus(struct soap *)" (?soap_serve_plus@@YAHPAUsoap@@@Z)
中被引用
1>stdsoap2.obj : error LNK2001: 无法解析的外部符号 _namespaces
1>D:\MyCode\SpasvoProc\Output\Debug\ClipBoard.exe : fatal error LNK1120: 2 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
第一个是因为只声明没有实现
将soapStub.h文件最后的函数放在另个文件中实现
SOAP_FMAC5 int SOAP_FMAC6 plus(struct soap*, int num_1, int num_2, int *sum)
{
*sum = num_1 + num_2;
printf("sum = %d", sum);
return SOAP_OK;
}
解决了一个问题
1>------ 已启动生成: 项目: ClipBoard, 配置: Debug Win32 ------
1> TestWebServer.cpp
1>stdsoap2.obj : error LNK2001: 无法解析的外部符号 _namespaces
1>D:\MyCode\SpasvoProc\Output\Debug\ClipBoard.exe : fatal error LNK1120: 1 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
百度一下
在工程中添加 WITH_NONAMESPACES宏//运行时会出错
#include "soap.nsmap"
编译通过
源文件中添加代码
#include "TestWebServer.h" #include "soapStub.h" #include "soap.nsmap" SOAP_FMAC5 int SOAP_FMAC6 plus(struct soap*, int num_1, int num_2, int *sum) { *sum = num_1 + num_2; printf("sum = %d", sum); return SOAP_OK; } int main() { struct soap math_service; soap_init(&math_service); if (soap_bind(&math_service, NULL, 8696, 0) == SOAP_ERR) { printf("%s", "bind false\n"); return -1; } printf("%s", "start server .....\n"); while (true) { int client = (int)soap_accept(&math_service); if (client < 0){ printf("%s", "accept client false!"); return -2; } printf("%s", "connect success\n"); soap_serve(&math_service); soap_end(&math_service); } return 0; }
运行之后浏览器输入http://localhost:8696/
显示
客户端新建一个工程项目,可以添加服务器生成的文件,也可以重新生成,
在客户端源文件中添加代码
#include "soap.nsmap" #include "soapStub.h" #include <stdlib.h> int main() { struct soap math_client; soap_init(&math_client); int sum = 0; const char *p_webservice = "http://127.0.0.1:8696"; soap_call_plus(&math_client, p_webservice, "", 60, 30, &sum); if (math_client.error){ soap_print_fault(&math_client, stderr); return -1; } printf("webService : 60 + 30 = %d", sum); soap_end(&math_client); soap_done(&math_client); getchar(); return 1; }
运行结果
客户端:
服务器端:
在会遇到中文乱码的情况下,typename.dat加上xsd::string = std::wstring | wchar_t*
Couldn't find a matching Java operation for WSDD operation
webService 函数名小写
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++高级程序员成长之路
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- 解析C++中派生的概念以及派生类成员的访问属性