BB 10 cascades + gsoap调用web service

         最近公司要做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;
	}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值