zoukankan      html  css  js  c++  java
  • gsoap、c++。webservice的client。

    背景需求。

    1、有一个webservice的server端。具体表现为一个link——http:\\XXXXXXXXXXXXXXXXXXX.com?wsdl

    2、下载一个最gsoap包,(自行前往官网下载)。解压目录为 D:\workspace\2、LIS\gsoap-2.8。

    操作流程。

    1、在 bin\win32 目录下建一个空的头文件WebService.h(好像可以不用做);

    2、再建立一个字符转换规则文件wsmap.dat,文件内容为xsd__string = | std::wstring | wchar_t*(为了某种程度上支持中文);

    3、启动cmd,进入到 \bin\win32 目录,调用wsdl2h.exe生成头文件接口定义,命令为:(生成.h文件)

    wsdl2h -o WebService.h -n WS -t wsmap.dat http://XXXXXXXXXXXXXXXXXXXXXX.asmx?WSDL

    此步完成后,WebService.h文件里面就有内容了。

    wsdl2h 的操作命令如下:

    • -o 文件名,指定输出头文件
    • -n 名空间前缀 代替默认的ns
    • -c 产生纯C代码,否则是C++代码
    • -s 不要使用STL代码
    • -t 文件名,指定type map文件,默认为typemap.dat
    • -e 禁止为enum成员加上名空间前缀

    4、在命令行输入soapcpp2 -j WebService.h(解析WebService.h,生成存根程序);

    然后生成的文件中包含server和client。做client千万不要把server加入其中。

    整个项目的源文件列表如下:

    main.cpp(玩家手动生成)

    soapC.cpp(本步骤生成)

    soapH.h(本步骤生成)

    soapLimsInfoServiceImplServiceSoapBindingProxy.cpp(本步骤生成)

    soapLimsInfoServiceImplServiceSoapBindingProxy.h(本步骤生成)

    soapStub.h(本步骤生成)

    stdsoap2.cpp(gsoap文件夹下有)

    stdsoap2.h(gsoap文件夹下有)

    5、新建项目。额外的文件列表入步骤4.

    在工程的头文件中加入#include “WeatherWSSoap.nsmap”,否则会有命名空间编译出错的问题.

    6、我的main代码

     1 #include "soapLimsInfoServiceImplServiceSoapBindingProxy.h"
     2 
     3 #include "LimsInfoServiceImplServiceSoapBinding.nsmap"
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     LimsInfoServiceImplServiceSoapBindingProxy webservice;
    10 
    11     WS1__getPatientInformation barcode = WS1__getPatientInformation();
    12 
    13     WS1__getPatientInformationResponse pantientRes = WS1__getPatientInformationResponse();
    14 
    15     string tmp = "157961253";
    16     barcode.WS1__barcode = &tmp;
    17 
    18     int result = webservice.getPatientInformation(&barcode, pantientRes);
    19 
    20     if (SOAP_OK == result)
    21     {
    22         cout << *pantientRes.out;
    23     }
    24 
    25     cin.get();
    26     return 0;
    27 }

     

     

  • 相关阅读:
    使用 Docker 部署 Spring Boot
    阿里云Redis开发规范
    Java开发包Jedis
    Jedis的配置和优化
    JVM调优前戏之JDK命令行工具---jhat
    JVM调优前戏之JDK命令行工具---jstack
    JVM调优之经验
    Logback配置文件这么写,TPS提高10倍
    Java开发包Jedis
    Error Handling in ASP.NET Core
  • 原文地址:https://www.cnblogs.com/yangtoujunshi/p/8418933.html
Copyright © 2011-2022 走看看