gsoap开发实例-查询腾讯QQ在线状态

开发环境:Windows XP sp3+VC6.0


//----------------------------lwnorth-----------------------------------------//

1 下载gsoap

gsoap下载地址: http://sourceforge.net/projects/gsoap2

本例中下载的是2.8.15版本的压缩文件gsoap_2.8.15.zip

解压后得到”gsoap-2.8”文件夹

笔者建立的目录为D:\soap\gsoap-2.8

//----------------------------lwnorth-----------------------------------------//

2 创建C++工程

打开VC6.0

新建工程File->New->Project->Win32Console Application

工程名称(Project Name): “Tencent”

工程位置(Location):”D:\SOAP\GSOAP-2.8\GSOAP\Tencent”

首先建立一个空的工程(An Empty Project),

 

新建C++文件File->New->C++Source File

工程名称(Project Name): “Tencent”

工程位置(Location):”D:\SOAP\GSOAP-2.8\GSOAP\Tencent”

 

将空白文件Tencent.cpp添加进工程:

“Tencentfiles”上点击鼠标右键->”Add File To Project”->选择Tencent.cpp 点击确定

至此 一个名为”Tencent”的工程创建完成

//----------------------------lwnorth-----------------------------------------//

3 腾讯QQ在线状态查询Web Service:

Web Service的URL是:

http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx

服务端WSDL的URL是:

http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

相关服务说明:

输入参数:QQ号码 String,默认QQ号码:8698053。返回数据:String,Y= 在线;N = 离线;E = QQ号码错误;A = 商业用户验证失败;V = 免费用户超过数量

//----------------------------lwnorth-----------------------------------------//

4 生成客户端所需的头文件及资源文件

运行命令提示符(“开始”->”运行”->输入cmd->”确定”)

改变当前路径到D:\soap\gsoap-2.8\gsoap\Tencent

 

首先使用wsdl2h生成头文件Tencent.h

Windows XP适用的Wsdl2h.exe的目录为D:\soap\gsoap-2.8\gsoap\bin\win32

在命令提示符中输入..\bin\win32\wsdl2h–o tencent.h http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

本例生成的是C++代码文件 如果希望生成C代码文件,加上-c(小写c) 参数即可

 

执行后命令提示符中显示:

D:\soap\gsoap-2.8\gsoap\Tencent>..\bin\win32\wsdl2h -o tencent.hhttp://www.webx

ml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

 

**  The gSOAP WSDL/Schemaprocessor for C and C++, wsdl2h release 2.8.15

**  Copyright (C) 2000-2013Robert van Engelen, Genivia Inc.

**  All Rights Reserved. Thisproduct is provided "as is", without any warranty.

 

**  The wsdl2h tool isreleased under one of the following two licenses:

**  GPL or the commerciallicense by Genivia Inc. Use option -l for details.

 

Saving tencent.h

 

Cannot open file 'typemap.dat'

Problem reading type map file 'typemap.dat'.

Using internal type definitions for C++ instead.

 

Connecting to 'http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

' to retrieve WSDL/XSD...

Connected, receiving...

Done reading'http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl'

 

Warning: 4 service bindings found, but collected as one service (useoption -Nna

me to produce a separate service for each binding)

 

Warning: ignoring REST operation 'qqCheckOnline' in binding'qqOnlineWebServiceH

ttpGet' (use option -R to enable REST)

 

Warning: ignoring REST operation 'qqCheckOnline' in binding'qqOnlineWebServiceH

ttpPost' (use option -R to enable REST)

 

To complete the process, compile with:

> soapcpp2 tencent.h

or to generate C++ proxy and object classes:

> soapcpp2 -j tencent.h

 

然后使用soapcpp2生成客户端相关的头文件、资源文件 在命令提示符中输入 ..\bin\win32\soapcpp2-C tencent.h(参数-C表示只生成客户端文件)

 

如果出现提示”Critical error:#import: Cannot open file "stlvector.h" for reading.

Hint: use option -I<path> (for example-Igsoap/import;gsoap/custom:.)”

表示找不到头文件stlvector.h 通过查找发现D:\soap\gsoap-2.8\gsoap\import路径下有这个文件 添加参数 -I..\import即可: ..\bin\win32\soapcpp2-C –I..\import tencent.h

 

执行后命令提示符中显示:

D:\soap\gsoap-2.8\gsoap\Tencent>..\bin\win32\soapcpp2 -C-I..\import tencent.h

 

**  The gSOAP code generatorfor C and C++, soapcpp2 release 2.8.15

**  Copyright (C) 2000-2013,Robert van Engelen, Genivia Inc.

**  All Rights Reserved. Thisproduct is provided "as is", without any warranty.

 

**  The soapcpp2 tool isreleased under one of the following two licenses:

**  GPL or the commerciallicense by Genivia Inc.

 

Saving soapStub.h annotated copy of the source input

Saving soapH.h interface declarations

Using ns1 service name: qqOnlineWebServiceSoap

Using ns1 service style: document

Using ns1 service encoding: literal

Using ns1 service location:http://www.webxml.com.cn/webservices/qqOnlineWebServ

ice.asmx

Using ns1 schema namespace: http://WebXml.com.cn/

Saving qqOnlineWebServiceSoap.qqCheckOnline.req.xml sample SOAP/XMLrequest

Saving qqOnlineWebServiceSoap.qqCheckOnline.res.xml sample SOAP/XMLresponse

Saving qqOnlineWebServiceSoap.qqCheckOnline.req.xml sample SOAP/XMLrequest

Saving qqOnlineWebServiceSoap.qqCheckOnline.res.xml sample SOAP/XMLresponse

Saving qqOnlineWebServiceSoap.nsmap namespace mapping table

Saving soapClient.cpp client calling stubs

Saving soapClientLib.cpp client stubs with serializers (use only forlibs)

Saving soapC.cpp serializers

 

Compilation successful

//----------------------------lwnorth-----------------------------------------//

5编写客户端程序

把以下文件添加进工程:

SoapH.h

SoapC.cpp

soapStub.h

soapClient.cpp

tencent.h

qqOnlineWebServiceSoap.nsmap

把D:\soap\gsoap-2.8\gsoap目录下的stdsoap2.h和stdsoap2.cpp文件拷贝到D:\soap\gsoap-2.8\gsoap\Tencent并且添加进工程

 

编写客户端程序(编辑Tencent.cpp文件),代码如下:

#include "soapH.h"
#include "qqOnlineWebServiceSoap.nsmap"
 
int main(int argc, char **argv)
{
       if ( argc != 2 )
       {
              printf("命令格式: %s QQ号码\n", argv[0]);
              exit(-1);
       }
       struct soap soap;
       soap_init(&soap);
       struct_ns1__qqCheckOnline request;
       struct_ns1__qqCheckOnlineResponse response;
       //QQ号码
       request.qqCode=newstd::string(argv[1]);
       intiResult=soap_call___ns1__qqCheckOnline(&soap,NULL,NULL,&request,&response);
       if (iResult==SOAP_OK)
       {
              if(response.qqCheckOnlineResult->compare("N")==0)
              {
                     printf("QQ:%s离线",argv[1]);
              }
              else if(response.qqCheckOnlineResult->compare("Y")==0)
              {
                     printf("QQ:%s在线",argv[1]);
              }
              else if(response.qqCheckOnlineResult->compare("E")==0)
              {
                     printf("%s号码错误",argv[1]);
              }
              else if(response.qqCheckOnlineResult->compare("A")==0)
              {           
                     printf("%s商业用户验证失败",argv[1]);
              }
              else if(response.qqCheckOnlineResult->compare("V")==0)
              {
                     printf("%s免费用户超过数量",argv[1]);
              }
              else
              {
                     printf("%s未知错误",argv[1]);
              }
       }
       else
       {
              soap_print_fault(&soap,stderr);
       }
       soap_destroy(&soap);
       soap_end(&soap);
       soap_done(&soap);
       return 0;
}


 

编译成功后生成可执行文件tencent.exe

//----------------------------lwnorth-----------------------------------------//

6 执行程序

在命令提示符中更改路径到tencent.exe所在路径 输入:”tencent qq号码”可查询QQ号是否在线

如:D:\soap\gsoap-2.8\gsoap\Tencent\Debug>tencent87654321

QQ:87654321 在线

//----------------------------lwnorth-----------------------------------------//

本文如有不当之处欢迎指正 转载请注明出处 谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值