1.客户端的生成
去官网下载源码
http://jaist.dl.sourceforge.net/project/gsoap2/gsoap-2.8/gsoap_2.8.108.zip
把gosap下面的stdsoap2.h和stdsoap2.cpp放到gosap/bin/win32下面,再把wsdl文件放到gosap/bin/win32
生成头文件.h
把soapC.cpp soapClient.cpp soapH.h soapStub.h stdsoap2.cpp stdsoap2.h 还有 *.nsmap
注意原来生成的头文件(不需要),如HTSAPServer.h
客户端具体代码如下:
#ifndef ifChengDao_h__
#define ifChengDao_h__
#include <stdio.h>
#include
//违法图片
typedef struct
{
/login返回的sid/
char *sid;
/设备编号/
char *pDeviceId;
/车辆编号/
char *pVehicleId;
/设备类型/
char *pDeviceType;
/方向编号/
char *pDirectionId;
/车道编号/
char *pDriveWayId;
/号牌号码/
char *pPlateNum;
/号牌类型/
char *pPlateType;
/经过时间/
char *pPassTime;
/红灯开始时间/
char *pRedStartTime;
/红灯持续时间/
char *pRedLastTime;
/车辆速度/
long nSpeed;
/大车限速/
long nLargeLimitSpeed;
/小车限速/
long nMinLimitSpeed;
/违章行为编码/
char *pIllegalType;
/可空/
char *pIllegalType2;
/车长 以厘米为单位 可空/
long nCarLen;
/号牌颜色/
char *pPlateColor;
/车辆类型/
char *pVehType;
/图片1 二进制/
unsigned char *__ptr1;
int __size1;
/*图片2 二进制*/
unsigned char *__ptr2;
int __size2;
/*图片1 二进制*/
unsigned char *__ptr3;
int __size3;
/*图片1 二进制*/
unsigned char *__ptr4;
int __size4;
/*图片5 人像图片 二进制*/
unsigned char *__ptr5;
int __size5;
/*图片6 号牌特写 二进制*/
unsigned char *__ptr6;
int __size6;
/*视频 二进制*/
unsigned char *__ptrVideo;
int __sizeVideo;
/*图片远程访问路径 可空*/
char *__pRemoteData;
/*违法标记 0普通记录 1违法记录非空*/
char *pViolate;
/*发送标志 "0"代表正常 "1"代表滞后发送 非空*/
char *pSendType;
/*违法地点编码*/
char *pPlaceId;
/*违法地点名称*/
char *pPlaceName;
/*车身颜色*/
char *pCarColor;
/*车身深度*/
/*保留字段1*/
char *pReseve1;
/*保留字段2*/
char *pReseve2;
/*保留字段3*/
char *pReseve3;
}TChengDao_VioInfo;
typedef struct
{
/login返回的sid/
char *pSid;
/过车信息项/
char *pXmlData;
/图片1 车辆全景图 二进制/
unsigned char *__ptr1;
int __size1;
/图片2 全景图片 二进制/
unsigned char *__ptr2;
int __size2;
/图片3 全景图片2 二进制/
unsigned char *__ptr3;
int __size3;
/图片4 备用 二进制/
unsigned char *__ptr4;
int __size4;
/图片5 人像图片 二进制/
unsigned char *__ptr5;
int __size5;
/图片6 号牌特写 二进制/
unsigned char *__ptr6;
int __size6;
/*视频 二进制*/
unsigned char *__ptrVideo;
int __sizeVideo;
}TChengDao_VehPassInfo;
#ifdef __cplusplus
extern “C” {
#endif
#ifndef API
#ifdef _MSC_VER
#define API __declspec(dllexport)
#else
#define API
#endif
#endif
API int ifChengDao__login(char *soap_endpoint, char *pDeviceId, char *pDeviceKey, char *szSidOut);
API int ifChengDao__logout(char *soap_endpoint, char *sId);
API int ifChengDao__setIllegalVehInfo(char *soap_endpoint, TChengDao_VioInfo *ptData);
API int ifChengDao__setPassVehInfo(char *soap_endpoint, TChengDao_VehPassInfo *ptData);
#ifdef __cplusplus
}
#endif
#endif // ifChengDao_h__
#include “soapH.h”
#include “ifChengDao.h”
#include “HTSAPServerSoapBinding.nsmap”
static void ExpDataWrite(char *fileName, char pInfo)
{
FILE fp1 = fopen(fileName, “ab+”);
if (fp1 == NULL)
{
return;
}
fprintf(fp1, “%s\n”, pInfo);
fclose(fp1);
}
API int ifChengDao__login(char *soap_endpoint, char *pDeviceId, char *pDeviceKey, char *szSidOut)
{
int nRet = 0;
struct soap g_tsoap;
ns1__login *ptLogin = soap_new_set_ns1__login(&g_tsoap, pDeviceId, pDeviceKey);
ns1__loginResponse loginResponse;
nRet = soap_call___ns1__login(&g_tsoap, soap_endpoint, NULL, ptLogin, loginResponse);
if (nRet != SOAP_OK)
{
printf("Error while calling the soap_call___ns1__login\n");
}
else
{
printf("Calling the soap_call___ns1__login success。\n");
}
if (loginResponse.return_)
{
sprintf(szSidOut, "%s", loginResponse.return_->c_str());
}
soap_end(&g_tsoap);
soap_destroy(&g_tsoap);
soap_done(&g_tsoap);
return nRet;
}
API int ifChengDao__logout(char *soap_endpoint, char *sId)
{
int nRet = 0;
struct soap g_tsoap;
ns1__logout *pLogout = soap_new_set_ns1__logout(&g_tsoap, sId);
ns1__logoutResponse logoutResponse;
nRet = soap_call___ns1__logout(&g_tsoap, soap_endpoint, NULL, pLogout, logoutResponse);
if (nRet != SOAP_OK)
{
printf(“Error while calling the soap_call___ns1__logout\n”);
}
else
{
printf(“Calling the soap_call___ns1__logout success。\n”);
}
soap_end(&g_tsoap);
soap_destroy(&g_tsoap);
soap_done(&g_tsoap);
return nRet;
}
API int ifChengDao__setIllegalVehInfo(char *soap_endpoint, TChengDao_VioInfo *ptData)
{
int nRet = 0;
struct soap g_tsoap;
xsd__base64Binary *tplj1 = new xsd__base64Binary();
tplj1->__size = ptData->__size1;
tplj1->__ptr = ptData->__ptr1;
xsd__base64Binary *tplj2 = new xsd__base64Binary();
tplj2->__size = ptData->__size2;
tplj2->__ptr = ptData->__ptr2;
xsd__base64Binary *tplj3 = new xsd__base64Binary();
tplj3->__size = ptData->__size3;
tplj3->__ptr = ptData->__ptr3;
xsd__base64Binary *tplj4 = new xsd__base64Binary();
tplj4->__size = ptData->__size4;
tplj4->__ptr = ptData->__ptr4;
xsd__base64Binary *tplj5 = new xsd__base64Binary();
tplj5->__size = ptData->__size5;
tplj5->__ptr = ptData->__ptr5;
xsd__base64Binary *tplj6 = new xsd__base64Binary();
tplj6->__size = ptData->__size6;
tplj6->__ptr = ptData->__ptr6;
xsd__base64Binary *tplj7 = new xsd__base64Binary();
tplj7->__size = ptData->__sizeVideo;
tplj7->__ptr = ptData->__ptrVideo;
ns1__NSyncWriteVioInfo *pIllegalData = soap_new_set_ns1__NSyncWriteVioInfo(&g_tsoap, ptData->sid,
ptData->pDeviceId, ptData->pVehicleId, ptData->pDeviceType, ptData->pDirectionId, ptData->pDriveWayId
, ptData->pPlateNum, ptData->pPlateType, ptData->pPassTime, ptData->pRedStartTime, ptData->pRedLastTime
, ptData->nSpeed, ptData->nLargeLimitSpeed, ptData->nMinLimitSpeed, ptData->pIllegalType, ptData->pIllegalType2
, ptData->nCarLen, ptData->pPlateColor, ptData->pVehType, *tplj1, *tplj2
,*tplj3,*tplj4,*tplj5,*tplj6,*tplj7, ptData->__pRemoteData, ptData->pViolate, ptData->pSendType
, ptData->pPlaceId, ptData->pPlaceName, “0”, “”, 0, 0, ptData->pCarColor, “”, “”, “”, ptData->pReseve1, ptData->pReseve2, ptData->pReseve3);
ns1__NSyncWriteVioInfoResponse tVioInfoResp;
nRet = soap_call___ns1__NSyncWriteVioInfo(&g_tsoap, soap_endpoint, NULL, pIllegalData, tVioInfoResp);
if (nRet != SOAP_OK)
{
printf("Error while calling the soap_call___ns1__NSyncWriteVioInfo\n");
}
else
{
printf("Calling the soap_new_set_ns1__NSyncWriteVioInfo success\n");
}
if (tVioInfoResp.return_)
{
printf("soap_new_set_ns1__NSyncWriteVioInfo Response:%s\n", tVioInfoResp.return_->c_str());
char tmpBuf[5] = { 0 };
memcpy(tmpBuf, tVioInfoResp.return_->c_str(), 4);
if (strcmp(tmpBuf, "0000") != 0)
{
printf("Calling the soap_new_set_ns1__NSyncWriteVioInfo failed\n");
}
}
delete tplj1;
delete tplj2;
delete tplj3;
delete tplj4;
delete tplj5;
delete tplj6;
delete tplj7;
soap_end(&g_tsoap);
soap_destroy(&g_tsoap);
soap_done(&g_tsoap);
return nRet;
}
API int ifChengDao__setPassVehInfo(char *soap_endpoint, TChengDao_VehPassInfo *ptData)
{
int nRet = 0;
struct soap g_tsoap;
xsd__base64Binary *tplj1 = new xsd__base64Binary();
tplj1->__size = ptData->__size1;
tplj1->__ptr = ptData->__ptr1;
xsd__base64Binary *tplj2 = new xsd__base64Binary();
tplj2->__size = ptData->__size2;
tplj2->__ptr = ptData->__ptr2;
xsd__base64Binary *tplj3 = new xsd__base64Binary();
tplj3->__size = ptData->__size3;
tplj3->__ptr = ptData->__ptr3;
xsd__base64Binary *tplj4 = new xsd__base64Binary();
tplj4->__size = ptData->__size4;
tplj4->__ptr = ptData->__ptr4;
xsd__base64Binary *tplj5 = new xsd__base64Binary();
tplj5->__size = ptData->__size5;
tplj5->__ptr = ptData->__ptr5;
xsd__base64Binary *tplj6 = new xsd__base64Binary();
tplj6->__size = ptData->__size6;
tplj6->__ptr = ptData->__ptr6;
xsd__base64Binary *tplj7 = new xsd__base64Binary();
tplj7->__size = ptData->__sizeVideo;
tplj7->__ptr = ptData->__ptrVideo;
ExpDataWrite((char*)"/usr/log/soInfo.txt", (char*)"soap_new_set_ns1__SyncWriteVehPassInfo start");
ns1__SyncWriteVehPassInfo *pVehInfo = soap_new_set_ns1__SyncWriteVehPassInfo(&g_tsoap, ptData->pSid, ptData->pXmlData, *tplj1
, *tplj2, *tplj3,*tplj4,* tplj5, *tplj6, *tplj7);
ExpDataWrite((char*)"/usr/log/soInfo.txt", (char*)"soap_new_set_ns1__SyncWriteVehPassInfo ---------222---");
ns1__SyncWriteVehPassInfoResponse vehPassInfoRsp;
nRet = soap_call___ns1__SyncWriteVehPassInfo(&g_tsoap, soap_endpoint, NULL, pVehInfo, vehPassInfoRsp);
ExpDataWrite((char*)"/usr/log/soInfo.txt", ( char*)"soap_new_set_ns1__SyncWriteVehPassInfo ---------3333---");
if (nRet != SOAP_OK)
{
printf("Error while calling the soap_new_set_ns1__SyncWriteVehPassInfo\n");
}
else
{
printf("Calling the soap_new_set_ns1__SyncWriteVehPassInfo success\n");
}
if (vehPassInfoRsp.return_)
{
ExpDataWrite((char*)"/usr/log/soInfo.txt", (char*)"soap_new_set_ns1__SyncWriteVehPassInfo ---------4444---");
printf("soap_new_set_ns1__SyncWriteVehPassInfo Response:%s\n", vehPassInfoRsp.return_->c_str());
char tmpBuf[5] = { 0 };
ExpDataWrite((char*)"/usr/log/soInfo.txt", (char*)"soap_new_set_ns1__SyncWriteVehPassInfo ---------5555---");
memcpy(tmpBuf, vehPassInfoRsp.return_->c_str(), 4);
if (strcmp(tmpBuf, "0000") != 0)
{
printf("Calling the soap_new_set_ns1__NSyncWriteVioInfo failed\n");
}
}
ExpDataWrite((char*)"/usr/log/soInfo.txt", (char*)"soap_new_set_ns1__SyncWriteVehPassInfo ---------6666---");
delete tplj1;
delete tplj2;
delete tplj3;
delete tplj4;
delete tplj5;
delete tplj6;
delete tplj7;
soap_end(&g_tsoap);
soap_destroy(&g_tsoap);
soap_done(&g_tsoap);
return nRet;
}
调用
int main()
{
char pRequset[256] = { “http://10.73.0.186:7081/21321/213” };
char sId[64];
int nRet = ifChengDao__login(pRequset, “123456789”, “0000000”, sId);
return 0;
}
服务器的实现
把soapC.cpp soapH.h soapServer.cpp soapStub.h stdsoap2.h stdsoap2.cpp 拷贝到工程中
具体的实现代码
#include
#include “soapH.h”
#include “HTSAPServerSoapBinding.nsmap”
#include <windows.h>
#include <tchar.h>
using namespace std;
int ns1__login(struct soap*, ns1__login *ns1__login, ns1__loginResponse &ns1__loginResponse)
{
printf(“Client is login\n”);
char str[100];
DWORD processId = GetCurrentProcessId();
DWORD sessionId;
ProcessIdToSessionId(processId, &sessionId);
if (ns1__login_->strDeviceId.c_str() != “” && ns1__login_->strDeviceKey.c_str() != “”)
{
sprintf(str,“0000^%u”,sessionId);
std::string *pStr = new std::string(str);
ns1__loginResponse_.return_ = pStr;
}
return SOAP_OK;
}
int ns1__logout(struct soap*, ns1__logout *ns1__logout, ns1__logoutResponse &ns1__logoutResponse)
{
printf(“Client id lgout\n”);
if (ns1__logout_->sid.c_str() != “”)
{
std::string *pStr = new std::string(“0000”);
ns1__logoutResponse_.return_ = pStr;
}
return SOAP_OK;
}
int ns1__NSyncWriteMobileEPVInfo(struct soap*, ns1__NSyncWriteMobileEPVInfo *ns1__NSyncWriteMobileEPVInfo, ns1__NSyncWriteMobileEPVInfoResponse &ns1__NSyncWriteMobileEPVInfoResponse)
{
return SOAP_OK;
}
int ns1__syncWriteVehicleInfo(struct soap*, ns1__syncWriteVehicleInfo *ns1__syncWriteVehicleInfo, ns1__syncWriteVehicleInfoResponse &ns1__syncWriteVehicleInfoResponse)
{
return SOAP_OK;
}
int ns1__writeVehicleInfo(struct soap*, ns1__writeVehicleInfo *ns1__writeVehicleInfo, ns1__writeVehicleInfoResponse &ns1__writeVehicleInfoResponse)
{
return SOAP_OK;
}
int ns1__queryLimitSpeed(struct soap*, ns1__queryLimitSpeed *ns1__queryLimitSpeed, ns1__queryLimitSpeedResponse &ns1__queryLimitSpeedResponse)
{
return SOAP_OK;
}
int ns1__queryViolateSpeed(struct soap*, ns1__queryViolateSpeed *ns1__queryViolateSpeed, ns1__queryViolateSpeedResponse &ns1__queryViolateSpeedResponse)
{
return SOAP_OK;
}
int ns1__querySyncTime(struct soap*, ns1__querySyncTime *ns1__querySyncTime, ns1__querySyncTimeResponse &ns1__querySyncTimeResponse)
{
return SOAP_OK;
}
int ns1__writeAlarmInfo(struct soap*, ns1__writeAlarmInfo *ns1__writeAlarmInfo, ns1__writeAlarmInfoResponse &ns1__writeAlarmInfoResponse)
{
return SOAP_OK;
}
int ns1__NWriteVehicleInfo(struct soap*, ns1__NWriteVehicleInfo *ns1__NWriteVehicleInfo, ns1__NWriteVehicleInfoResponse &ns1__NWriteVehicleInfoResponse)
{
return SOAP_OK;
}
int ns1__NWriteVehicleInfoEx(struct soap*, ns1__NWriteVehicleInfoEx *ns1__NWriteVehicleInfoEx, ns1__NWriteVehicleInfoExResponse &ns1__NWriteVehicleInfoExResponse)
{
return SOAP_OK;
}
int ns1__NSyncWriteVehicleInfo(struct soap*, ns1__NSyncWriteVehicleInfo *ns1__NSyncWriteVehicleInfo, ns1__NSyncWriteVehicleInfoResponse &ns1__NSyncWriteVehicleInfoResponse)
{
return SOAP_OK;
}
int ns1__WriteFlux(struct soap*, ns1__WriteFlux *ns1__WriteFlux, ns1__WriteFluxResponse &ns1__WriteFluxResponse)
{
return SOAP_OK;
}
int ns1__NWriteDeviceStatus(struct soap*, ns1__NWriteDeviceStatus *ns1__NWriteDeviceStatus, ns1__NWriteDeviceStatusResponse &ns1__NWriteDeviceStatusResponse)
{
return SOAP_OK;
}
int ns1__NSyncWriteVioInfo(struct soap*, ns1__NSyncWriteVioInfo *ns1__NSyncWriteVioInfo, ns1__NSyncWriteVioInfoResponse &ns1__NSyncWriteVioInfoResponse)
{
printf(“Client is send IllegeInfo\n”);
char str[100];
if (ns1__NSyncWriteVioInfo_->sid != “” && ns1__NSyncWriteVioInfo_->strDeviceId != “” && ns1__NSyncWriteVioInfo_->strDirectionId != “” && ns1__NSyncWriteVioInfo_->strVehicleId != “”)
{
std::string *pStr = new std::string(“0000”);
ns1__NSyncWriteVioInfoResponse_.return_ = pStr;
}
return SOAP_OK;
}
int ns1__NWritePassStat(struct soap*, ns1__NWritePassStat *ns1__NWritePassStat, ns1__NWritePassStatResponse &ns1__NWritePassStatResponse)
{
return SOAP_OK;
}
int ns1__SyncWriteVehPassInfo(struct soap*, ns1__SyncWriteVehPassInfo *ns1__SyncWriteVehPassInfo, ns1__SyncWriteVehPassInfoResponse &ns1__SyncWriteVehPassInfoResponse)
{
printf(“Client is send VehPassInfo\n”);
if (ns1__SyncWriteVehPassInfo_->sid != “” && ns1__SyncWriteVehPassInfo_->xmlParam != “”)
{
std::string *pStr = new std::string(“0000”);
ns1__SyncWriteVehPassInfoResponse_.return_ = pStr;
}
return SOAP_OK;
}
int ns1__WriteVehPassInfo(struct soap*, ns1__WriteVehPassInfo *ns1__WriteVehPassInfo, ns1__WriteVehPassInfoResponse &ns1__WriteVehPassInfoResponse)
{
return SOAP_OK;
}
int ns1__SyncWriteAreaSpeed(struct soap*, ns1__SyncWriteAreaSpeed *ns1__SyncWriteAreaSpeed, ns1__SyncWriteAreaSpeedResponse &ns1__SyncWriteAreaSpeedResponse)
{
return SOAP_OK;
}
int ns1__WriteAreaSpeed(struct soap*, ns1__WriteAreaSpeed *ns1__WriteAreaSpeed, ns1__WriteAreaSpeedResponse &ns1__WriteAreaSpeedResponse)
{
return SOAP_OK;
}
int main()
{
struct soap *serversoap = soap_new();
int socket_master = soap_bind(serversoap, NULL, 7081, 100);
if (socket_master < 0)
{
soap_print_fault(serversoap, stderr);
exit(-1);
}
printf(“SoapBind success,the master socket number is:%d\n”, socket_master);
while (1)
{
int socket_listen = soap_accept(serversoap);
if (socket_listen < 0)
{
soap_print_fault(serversoap, stderr);
exit(-2);
}
printf("Get a new connection,the slaver socket number is:%d\n", socket_listen); //绑定成功返回监听套接字
soap_serve(serversoap);
soap_end(serversoap);
}
soap_done(serversoap);
free(serversoap);
return 0;
}
注意 服务器需要把所有的接口都要写出来,要不然会报LNK2019
gsoap具体选项可参考如下:
https://blog.csdn.net/originalcandy/article/details/83054794
https://blog.csdn.net/byxdaz/article/details/51679117