Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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;
 		// TODO: Place code here.

		//MSG msg;
		//HACCEL hAccelTable;

		// Initialize global strings

		//LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
		//LoadString(hInstance, IDC_ZPRTFILEPOST, szWindowClass, MAX_LOADSTRING);
		//MyRegisterClass(hInstance);

		// Perform application initialization:
		if (!InitInstance (hInstance, nCmdShow))
		{
			return FALSE;
		}

		//hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ZPRTFILEPOST));

		// Main message loop:
		/*while (GetMessage(&msg, NULL, 0, 0))
		{
			if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}

		return (int) msg.wParam;*/

		BOOL bReturn=GetModulePath(g_szAppLogPath);

		//memset(g_szRegID,0,sizeof(g_szRegID));
		//GetSAAZODPath(g_szRegID);
		lstrcpy(g_szLogDirectory,g_szAppLogPath);
		strcat(g_szLogDirectory,"\\ApplicationLog\\zNWbPost.Log");

		//adjust the token priviledge, so it could terminate the exe properly
		if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) 
		{
			//Enable the SE_DEBUG_NAME privildge
			if(!EnablePrivilege(hToken, SE_DEBUG_NAME, TRUE)) 
			{
			}

			//Close the token handle
			CloseHandle(hToken);
			hToken = NULL;
		}

		////////////////////////////////////////////////////////////////////////////
		
		// Logic To Check Prev Instance , If is is there , exit... maintain a count in INI . Max Count = 5 .

		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, // Default Value = 6 means kill the inst.
										     szWebPostIniPath);

			if(nResult >= 5)
			{
				nResult = KillProcess(); // Count >= 5 ,Kill The Inst.
				WritePrivateProfileString("WebPostInfo",
									      "RunCount",
									      "0",
									      szWebPostIniPath);// Reset the Count=0 in INI
			}
			else
			{
				nResult++;
				char Temp[2] = {0};
				_itoa(nResult,Temp,10);

				WritePrivateProfileString("WebPostInfo",
										"RunCount",
										Temp,
										szWebPostIniPath); // Increase Count in INI
				::ReleaseMutex(hGlobalMutex);
				CloseHandle(hGlobalMutex);
				hGlobalMutex = NULL;
				Write_W3C_Log("zNWbPost","1.0","ERR:","ERR:   Instance already running","","","");
				return 0;
			}
		}

		WritePrivateProfileString("WebPostInfo",
									      "RunCount",
									      "0",
									      szWebPostIniPath);// Reset the Count=0 in INI

		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");

		/*if(FALSE == g_objWinHTTP.ZLoadWinHTTPDll())
		{
			g_bWinHTTPAvl	=	FALSE;
			Write_W3C_Log("zNWbPost","1.0","ERR:","ERR: Unable to load Win Http Dll","","","");
		}
		else 
		{
			g_bWinHTTPAvl	=	TRUE;
		}*/

		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,"","");

		//CoInitialize(NULL);
		HRESULT hResult = S_OK;
		//hResult=g_pChkXml.CreateInstance("{CE2E4226-494A-4DB2-9B45-7C8586CC01A3}");
		//hResult=g_pChkXml.CreateInstance(TEXT("ChilkatXml.ChilkatXml.1"));
		
		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);
		

		//zWpSupport
		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;
		//	g_pChkXml.Release();
			closeDll();
			g_nFold = 0;
			return 1;
		}
		
		bReturn= ReadXMLFile(g_szFileName);// Read The Main XML Config file
					
		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;
			//	g_pChkXml.Release();
				closeDll();
				g_nFold = 0;
				return 1;
			}
			
			Sleep(1000*60);

			bReturn= ReadXMLFile(g_szFileName);// Read The Main XML Config file
					
			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;
			//	g_pChkXml.Release();
				closeDll();
				g_nFold = 0;
				Write_W3C_Log("zNWbPost","1.0","ERR","Loading WpConfig.Xml Failed After Download","","","");
				return 1;
			}
		}
		
		objCMapFileData = new CMapFileData(); // Allocate Memory to Class Pointer
		
		for( int nFolderCnt = 0 ;nFolderCnt < g_nFold ; nFolderCnt++) // Taking File Info of Folders
		{
			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++)// Numbers Of Priority is Hardcoded [1,2,3]
		{
			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);
			}
		}

		// Free The Memory

		delete objCMapFileData; 

		//objCMapFileData = NULL;

		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;
			//g_pChkXml.Release();
			closeDll();
			g_nFold = 0;
		}
		catch(...)
		{
			return 1;
		}
	}
	catch(...)
	{
	
	}

	Write_W3C_Log("zNWbPost","1.0","INFO","","END","","");
	return 0;
}
Posted
Comments
Richard MacCutchan 31-Jul-15 3:50am    
You don't seriously believe that anyone is going to analyse that code for you? Explain what the problem is and where it occurs.
Member 11460314 31-Jul-15 4:31am    
sure. i just want to know how to pick up my xml file and put it on wcf url link
Member 11460314 31-Jul-15 4:53am    
oh thnks i have already done this. now the only thing which i have to do is send my xml data to wcf link (i.e hit my xml data on wcf). after it hits wcf URL, from there the logic i have already written and it works successfully.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900