BB 10 cascades + gsoap调用web service

来源:互联网 发布:鬼遮眼网络大电影 编辑:程序博客网 时间:2024/05/17 22:59

         最近公司要做BB 10的项目,需要用到Web service,因为Cascades是qml和qt结合,于是到网上查了一些qt方面的资料,参考了tingsking18的博客,找到gsoap的这个工具包,具体地址:http://www.cs.fsu.edu/~engelen/soap.html。

        把gsoap工具包下下来,解压到D盘,然后按tingsking18的操作,创建D:\gsoap文件夹,把/gsoap-2.8/gsoap/bin/win32下的stdsoap2.cpp和stdsoap2.h两个文件拷贝到/gsoap下,打开cmd, cd D:\gsoap,
        执行下面的命令行: 
        D:\gsoap>wsdl2h -o ReminderAuthenService.h http://xxx.xxx.xxx.xxx/ReminderWeb/WebService/AuthenticationService.asmx?wsdl
        生成头文件D:\gsoap\ReminderAuthenService.h。

再执行如下命令行:
 
      D:\gsoap>soapcpp2 -j ReminderAuthenService.h   

(-j选项表示不生成SOAP__ENV_Header 和SOAP_ENV__Details的定义,而且最后生成的客户端和服务端的cpp, .h命名不同)

出现错误:
 Critical error: #import: Cannot open file "stlvector.h" for reading.
 
Hint: use option -I<path> (for example -Igsoap/import;gsoap/custom:.)
需要import stlvector.h

解决方法:
  D:\gsoap>soapcpp2 -j -I "D:\Program Files\gsoap-2.8\gsoap\import" ReminderAuthenService.h
 
最后生成:
 XXXSoapProxy.cpp      
  XXXSoapProxy.h
 
XXXSoapService.cpp    XXXSoapService.h
 soapC.ccp            
         soapH.h  soapStub.h
 XXXSoap.nsmap   

还有一些xml文件,但在工程中不需要

代理类都生成好了,除了service类,xml文件不需要,其他的都放到自己bb10的工程中src/gsoap下面,然后编译,报了个错误:/src/gsoap/stdsoap2.cpp:8846: undefined reference to 'namespaces',意思是找不到namespaces,经查证是没有在stdsoap2.cpp中导入XXXSoap.nsmap文件。

编译成功,终于可以使用代理类了,以自己的工程为例:web service中有一个AuthenticationUserExisted(string username, string password, ClientUser user)方法(ClientUser为自定义类型)。具体实现:

//导入soap代理的头文件, 刚开始我以为代理类名和这个生成的头文件名是一样的,后面发现要去掉那个"soap"#include "soapAuthenticationServiceSoapProxy.h"//用户登录测试quint16 ReminderServiceUtils::loginTest(const QString &account, const QString &password){qDebug()<<"starting login";//Soap代理类AuthenticationServiceSoapProxy soap;//请求类_ns1__AuthenticationUserExisted *request = new _ns1__AuthenticationUserExisted();//返回类_ns1__AuthenticationUserExistedResponse *response = new _ns1__AuthenticationUserExistedResponse();//传入参数std::string usertemp = account.toStdString();request->_USCOREusername = &usertemp;std::string passtemp = password.toStdString();request->_USCOREpassword = &passtemp;//这个ns1__ClientUser参数只是作为数据返回时回调用的;//初始化了第一个成员变量ns1__ClientUser *cUser = new ns1__ClientUser();cUser->Guid = "4D9CC699-998A-18D1-6550-5A3E699AA45B";  //任意guid//std::string userTemp = "cai";//cUser->FirstName = &userTemp;//cUser->LastName = &userTemp;//cUser->UserName = &userTemp;//  cUser->ReminderList = new ns1__ArrayOfClientReminderTerminal();request->ClientUser = cUser;//调用web service方法soap.AuthenticationUserExisted(request, response);//返回结果, int型值return response->AuthenticationUserExistedResult;}



原创粉丝点击