加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Qt编写WebService客户端 (gsoap)

发布时间:2020-12-16 23:35:19 所属栏目:安全 来源:网络整理
导读:?http://blog.chinaunix.net/uid-24118190-id-4230340.html Qt编写WebService客户端? 2014-04-28 18:58:09 分类:? 其他平台 点击( 此处 )折叠或打开 / * #filename: main.cpp prj : ?Qt编写WebService客户端 date : ?2014 - 4 - 28 auth : ?pz 假设已经有一
?http://blog.chinaunix.net/uid-24118190-id-4230340.html
Qt编写WebService客户端? 2014-04-28 18:58:09

分类:?其他平台


点击(此处)折叠或打开

  1. /*
  2. #filename: main.cpp

  3. prj:?Qt编写WebService客户端
  4. date:?2014-4-28
  5. auth:?pz

  6. 假设已经有一个ws服务端在运行,提供由用户id查询用户名的服务,下面直接使用其soap服务定义?.h 文件在qt中开发客户端。



  7. 1.?准备
  8. 1.1 create directory:
  9. soaptest/client/
  10. soaptest/gsoap/

  11. 1.2 DOWNLOAD gsoap_2.8.15.zip,?extract following file/directory?to?soaptest:
  12. gsoap_2gsoap-2bin_win32
  13. gsoap_2{stdsoap2.h.cpp}
  14. gsoap_2import

  15. 2.?soapcpp2 编译
  16. 2.1 edit soap H filetest.h
  17. ==
  18. /gsoap ns service name:?cu
  19. /gsoap ns service namespace:?http:/localhost/cu.wsdl
  20. /gsoap ns service?location/home/cu
  21. /gsoap ns service executable:?cu.cgi
  22. /gsoap ns service encoding:?encoded
  23. /gsoap ns schema namespace:?urn:cu
  24. /gsoap ns schema?form:?unqualified


  25. struct ns__MyTestRequest
  26. {
  27. ????char*?id;
  28. };

  29. struct ns__MyTestResponse
  30. {
  31. ????int?Result;
  32. ????char*?name;

  33. int?ns__MyTest(struct ns__MyTestRequest?*req*rsp)=

  34. 2.2 soapcpp2
  35. EQtQtGuiExsoaptest>?bin_win32soapcpp2?-j?-I"./import"?test.h

  36. Note:
  37. -C generate webservice client
  38. -c pure c
  39. -j with proxy

  40. 3.?编译客户端
  41. 根据上一步 soapcpp2 是否带选项?-j,打开/关闭下面的宏定义,然后编译qt程序。
  42. #define USING_PROXY?-j

  43. 4.?运行结果
  44. 输入 id="pz"
  45. 输出 name?=?"pengzhen"

  46. */



  47. #include?<QApplication>
  48. #include?<QDebug<QWidget>
  49. #include?"../gsoap/cu.nsmap"

  50. -j
  51. const?char?*endpoint"http://192.168.250.101:9000/cu";

  52. #ifdef USING_PROXY

  53. /?with proxy
  54. #include?"../gsoap/soapcuProxy.h"
  55. int?main(int?argc*argv[])
  56. {
  57. ????cuProxy soapX;

  58. ????struct ns__MyTestRequest req?=?{"pz";
  59. ????struct ns__MyTestResponse res;



  60. ??soapX.MyTest(endpointNULL&req&res;
  61. ??qDebug(<<?"result:"?<?res.Result;
  62. ??if(res.Result?=?0)
  63. ??{
  64. ??????qDebug)?"name of "?<?req.id?":"?.name}

  65. return 0}

  66. #else

  67. /?without proxy
  68. #include?"../gsoap/soapH.h"

  69. {
  70. ????struct soap soapX;
  71. ????soap_init&soapX;
  72. ????/soap_set_namespaces;
  73. ????soap_set_mode;

  74. ??soap_call_ns__MyTest{
  75. ????qDebug}



  76. return 0}
  77. #endif
qt工程文件:

点击(此处)折叠或打开

# filename:?cli.pro
  • LIBS?+-lwsock32

  • SOURCES?
  • ????main.cpp?
  • ????.soapCsoapClientstdsoap2.cpp

  • #?for?proxy
  • SOURCES?soapcuProxy.cpp
  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读