gsoap搭建webservice-client

1.创建win32控制台工程webservice-client

2.将stdsoap2.hstdsoap2.cppinterface.nsmapsoapH.hsoapClient.cppsoapStub.hsoapC.cppstringEx.h拷贝到webservice-client目录下,添加到工程(使用预编译头->”否”);

3.新增webservice-client/interfaceFunc.hwebservice-client/interfaceFunc.cpp

#ifndef _INTERFACEFUNC_H
#define _INTERFACEFUNC_H
 
#include "stdsoap2.h"
#include "soapStub.h"
 
int func_add(const char* pszServer, int num1, int num2, int *nSum);
 
#endif

#include "interfaceFunc.h"
 
int func_add(const char* pszServer, int num1, int num2, int *nSum)
{
int nResult = 0;
struct soap stAddSoap;
soap_init(&stAddSoap);
//soap_set_namespaces(&stAddSoap, add_namespaces);
 
// 该函数是客户端调用的主要函数,后面几个参数和interface.h中声明的一样,前面多了个参数,函数名是接口函数名ns__add前面加上soap_call_
soap_call_ns__add(&stAddSoap, pszServer, "", num1, num2, nSum);
if (stAddSoap.error)
{
std::cout << "soap error:" << stAddSoap.error << ", "
<< *soap_faultcode(&stAddSoap) << ", " << *soap_faultstring(&stAddSoap)
<< std::endl;
nResult = stAddSoap.error;
} 
soap_end(&stAddSoap);
soap_done(&stAddSoap);
return nResult;
}

4.编写主线程入口函数_tmain

// webservice-client.cpp : 定义控制台应用程序的入口点。
//
 
#include "stdafx.h"
 
#include "stringEx.h"
#include "soapH.h"
#include "interfaceFunc.h"
#include "interface.nsmap"
 
int _tmain(int argc, _TCHAR* argv[])
{
int nNumber1 = 0, nNumber2 = 0, nSum = 0;
char *pszServer = "http://localhost:8101";
if (argc < 3)
{
std::cout << "usage:" << argv[0] << " num1 num2" << std::endl;
return 0;
}
 
char *pszNum = THCAR2char(argv[1]);
nNumber1 = atoi(pszNum);
delete []pszNum;
pszNum = THCAR2char(argv[2]);
nNumber2 = atoi(pszNum);
delete []pszNum;
pszNum = NULL;
 
int nResult = func_add(pszServer, nNumber1, nNumber2, &nSum);
if (nResult != 0)
{
std::cout << "soap error:" << nResult << std::endl;
}
else
{
std::cout << nNumber1 << " + " << nNumber2 << " = " << nSum << std::endl;
}
 
system("pause");
return 0;
}

5.带参数调试运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值