hi guys,
i have a task to do in c++ where in i have to pick up xml file from particular folder and then send that xml file to WCF web service from where the data of xml file will be inserted into its respected tables in database
i have the following code which does the same process successfully but for normal asp pages. now the same i have to implement it for wcf services using c++.
how can i do?
my wcf url= https://rmmagent.itsupport.net/AssetService.svc/rest/agent/asset
henceforth can any one tell me how must i include the above requirements in below written code?
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
try
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HANDLE hToken = NULL;
HANDLE hGlobalMutex = NULL;
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
BOOL bReturn=GetModulePath(g_szAppLogPath);
lstrcpy(g_szLogDirectory,g_szAppLogPath);
strcat(g_szLogDirectory,"\\ApplicationLog\\zNWbPost.Log");
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
if(!EnablePrivilege(hToken, SE_DEBUG_NAME, TRUE))
{
}
CloseHandle(hToken);
hToken = NULL;
}
hGlobalMutex = ::CreateMutex(NULL,FALSE,SAAZ_GLOBAL_MULTIWEBPOST_MUTEX29);
if(NULL == hGlobalMutex)
{
Write_W3C_Log("zNWbPost","1.0","ERR:","ERR: Unable to create global mutex","","","");
return 0;
}
int nResult = 0;
char szWebPostIniPath[512]={0};
sprintf(szWebPostIniPath,"%s\\zMWebPost.ini",g_szAppLogPath);
if(WAIT_OBJECT_0 != ::WaitForSingleObject(hGlobalMutex,((2)) * 1000))
{
nResult = ::GetPrivateProfileInt("WebPostInfo",
"RunCount",
6,
szWebPostIniPath);
if(nResult >= 5)
{
nResult = KillProcess();
WritePrivateProfileString("WebPostInfo",
"RunCount",
"0",
szWebPostIniPath);
}
else
{
nResult++;
char Temp[2] = {0};
_itoa(nResult,Temp,10);
WritePrivateProfileString("WebPostInfo",
"RunCount",
Temp,
szWebPostIniPath);
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
Write_W3C_Log("zNWbPost","1.0","ERR:","ERR: Instance already running","","","");
return 0;
}
}
WritePrivateProfileString("WebPostInfo",
"RunCount",
"0",
szWebPostIniPath);
int nNumOfFiles = 0;
char szWebPostFolderPath[512]={0};
sprintf(szWebPostIniPath,"%s\\NdataPost",g_szAppLogPath);
nNumOfFiles = NumOfFilesInFolder(szWebPostIniPath);
if(nNumOfFiles == 0)
{
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
Write_W3C_Log("zNWbPost","1.0","INFO","","START","","");
Write_W3C_Log("zNWbPost","1.0","INFO:","No Files In Folder","","","");
Write_W3C_Log("zNWbPost","1.0","INFO","","END","","");
return 0;
}
lstrcpy(g_szSAAZMobileINI,g_szAppLogPath);
lstrcat(g_szSAAZMobileINI,"\\SAAZMobile.INI");
lstrcpy(g_szWebPostPath,g_szAppLogPath);
lstrcat(g_szWebPostPath,"\\zWebPost.dll");
Sleep(200);
hinstLib = LoadLibrary(g_szWebPostPath);
if (hinstLib == NULL)
{
Write_W3C_Log("zNWbPost","1.0","ERR","zWebPost Loading Failed","","","");
return 1;
}
WebPostApi = (WEBPOST) GetProcAddress(hinstLib,"WebPostData");
if(WebPostApi == NULL)
{
Write_W3C_Log("zNWbPost","1.0","ERR","WebPostApi Loading Failed","","","");
return 1;
}
Sleep(200);
GetMachineInfo();
Write_W3C_Log("zNWbPost","1.0","INFO","","START","","");
Write_W3C_Log("zNWbPost","1.0","INFO","RegId:",g_szRegID,"","");
sprintf(g_szFileName,"%s\\Configuration\\WpConfig.Xml",g_szAppLogPath);
Write_W3C_Log("zNWbPost","1.0","INFO","Config FilePath",g_szFileName,"","");
HRESULT hResult = S_OK;
if(FAILED(hResult))
{
char ChilkatBuff[512]={0};
lstrcpy(ChilkatBuff,g_szAppLogPath);
strcat(ChilkatBuff,"\\ChilkatXml.dll");
int nResult = RegSvr(ChilkatBuff,1);
if(nResult > 0)
{
Write_W3C_Log("zNWbPost","1.0","ERR","ChilkatXml.dll CreateInstance Failed","","","");
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
return 1;
}
Write_W3C_Log("zNWbPost","1.0","MSG","ChilkatXml.dll Reg. Success","","","");
}
Sleep(200);
BOOL bZwpsupport=ObjCzWpSupport.DoInitializeSettings();
if(bZwpsupport == FALSE)
{
char ZwpBuff[512]={0};
lstrcpy(ZwpBuff,g_szAppLogPath);
strcat(ZwpBuff,"\\ChilkatCrypt2.dll");
int nResult = RegSvr(ZwpBuff,1);
if(nResult == 0)
{
Write_W3C_Log("zNWbPost","1.0","MSG","ChilkatCrypt2.dll Reg. Success","","","");
memset(ZwpBuff,0,sizeof(ZwpBuff));
lstrcpy(ZwpBuff,g_szAppLogPath);
strcat(ZwpBuff,"\\zWPSupport.dll");
nResult =1;
nResult = RegSvr(ZwpBuff,1);
if(nResult > 0)
{
Write_W3C_Log("zNWbPost","1.0","ERR","zWPSupport.dll CreateInstance Failed","","","");
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
return 1;
}
Write_W3C_Log("zNWbPost","1.0","MSG","zWPSupport.dll Reg. Success","","","");
}
else
{
Write_W3C_Log("zNWbPost","1.0","ERR","ChilkatCrypt2.dll CreateInstance Failed","","","");
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
return 1;
}
}
Sleep(50);
int nWpTemExe = ChkZWpTempleteProcess();
if(nWpTemExe == 1)
{
Write_W3C_Log("zNWbPost","1.0","MSG","ZWpTemplete Running, Exe Exits","","","");
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
return 1;
}
bReturn= ReadXMLFile(g_szFileName);
if(bReturn == FALSE)
{
Write_W3C_Log("zNWbPost","1.0","ERR","Loading WpConfig.Xml Failed 1 Attempt","","","");
char szGetWbtemplate[512] = {0};
PROCESS_INFORMATION piProcInfo = {0};
STARTUPINFO sInfoA = {0};
memset(szGetWbtemplate,0,sizeof(szGetWbtemplate));
lstrcpy(szGetWbtemplate,g_szAppLogPath);
lstrcat(szGetWbtemplate,"\\zWpTemplate.exe");
memset(&sInfoA,NULL,sizeof(sInfoA));
memset(&piProcInfo,NULL,sizeof(piProcInfo));
sInfoA.cb = sizeof(STARTUPINFO);
sInfoA.lpDesktop = "winsta0\\default";
BOOL bRetCP = ::CreateProcess(NULL,
szGetWbtemplate,
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS ,
NULL,
NULL,
&sInfoA,
&piProcInfo);
if(0 == bRetCP)
{
long lLastError = ::GetLastError();
char szError[100]={0};
_itoa(lLastError,szError,10);
Write_W3C_Log("zNWbPost","1.0","ERR","Create Process Failed For GetWbtemplate.exe","Code:",szError,"");
Write_W3C_Log("zNWbPost","1.0","ERR","Loading WpConfig.Xml Failed","","","");
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
return 1;
}
Sleep(1000*60);
bReturn= ReadXMLFile(g_szFileName);
if(bReturn == FALSE)
{
Write_W3C_Log("zNWbPost","1.0","ERR","Loading WpConfig.Xml Failed 2 Attempt","","","");
for(int cnt=0;cnt < MAX_PATH;cnt++)
{
if((pszFolder[cnt] != NULL) && (pszFolder[cnt] > 0) )
{
delete []pszFolder[cnt];
pszFolder[cnt] = NULL;
}
else
{
break;
}
}
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
Write_W3C_Log("zNWbPost","1.0","ERR","Loading WpConfig.Xml Failed After Download","","","");
return 1;
}
}
objCMapFileData = new CMapFileData();
for( int nFolderCnt = 0 ;nFolderCnt < g_nFold ; nFolderCnt++)
{
if(strcmp(pszFolder[nFolderCnt],"PMSTATUS") != 0)
{
sprintf(g_szFolderPath,"%s\\%s",g_szAppLogPath,pszFolder[nFolderCnt]);
Write_W3C_Log("zNWbPost","1.0","INFO","Taking Folder Files Info From:",g_szFolderPath,"","");
bReturn=Folderfun(g_szFolderPath,objCMapFileData);
}
}
char szTempSendData[MAX_PATH]={0};
for(int nPrtCnt = 0 ; nPrtCnt < 3 ; nPrtCnt++)
{
if(g_nFileCount < 51)
{
sprintf(szTempSendData,"WebPost Start's For Files Having Priority = %d ",nPrtCnt+1);
Write_W3C_Log("zNWbPost","1.0","INFO",szTempSendData,"","","");
memset(szTempSendData,0,sizeof(szTempSendData));
SendData(nPrtCnt + 1);
Sleep(150);
}
}
delete objCMapFileData;
for(int cnt=0;cnt < MAX_PATH; cnt++)
{
if((pszFolder[cnt] != NULL) && (pszFolder[cnt] > 0) )
{
delete []pszFolder[cnt];
pszFolder[cnt] = NULL;
}
else
{
break;
}
}
try
{
::ReleaseMutex(hGlobalMutex);
CloseHandle(hGlobalMutex);
hGlobalMutex = NULL;
closeDll();
g_nFold = 0;
}
catch(...)
{
return 1;
}
}
catch(...)
{
}
Write_W3C_Log("zNWbPost","1.0","INFO","","END","","");
return 0;
}