最近闲来看了看vc++编程,一直习惯C#和JAVA编程,不太习惯VC++的自己动手,丰衣足食的特点。测试的Web Service是以前写的一个发送短信的接口,这次step by step的讲一下如何进行vc++调用。
1.使用VS.NET2003 新建一个“Visual C++项目”,选择“Win32 控制台项目”,您也可建立“MFC应用程序”或“Win32 项目”,随个人喜好吧!
2.“添加 Web 引用”,输入URL地址,例如:http://www.xxx.com/WebService/Service1.asmx?wsdl,这里我们需要的是WSDL文件的申明,需要注意的是,在文件中如果Request和Response的namespace不相同时,VC++引用时会失败,大家可以观察一下。
3.下来进行编码操作,需要调用头文件comutil.h,事例代码(敏感数据被隐去):
// MYTEST.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "ZXT.h"
#include "CBase64.h"
#include "comutil.h"
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
BSTR p_szUserLoginID = _com_util::ConvertStringToBSTR("139xxxxxxxxx");
BSTR p_szPasswd = _com_util::ConvertStringToBSTR("*********");
CString cstr_szContent = "VC ++的Web Service>发送短信测试";
BSTR p_szSendTime = _com_util::ConvertStringToBSTR("");
BSTR p_szTargTel = _com_util::ConvertStringToBSTR("139xxxxxxxxx");
int p_iDispTel = 1;
int GZMCC_SendMsgServiceResult;
int ret;
BSTR desc;
BSTR zxtid;
BSTR feecode;
BSTR feetype;
BSTR feeltel;
BSTR content;
BSTR sendtime;
BSTR targtel;
ZxtSendMsgService::CZxtSendMsgService *service1 = new ZxtSendMsgService::CZxtSendMsgService();
CBase64* base64 = new CBase64();
cstr_szContent =