CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002
    Location
    Banglore
    Posts
    322

    CInternetSession Caching

    Hi,

    I'm accessing a RESTful service (Created in .net) through the CInternetSession object.

    I'm successfully able to get the response. But my problem is that after the first call it is getting the same data which it is got first time (maybe caching). If i close the application and then restarts then it gets the fresh data.

    Here is the code snippet

    Code:
    const CString UtilityClass::GetResultFromWebService(CString strPrefix, CString strURL, int &nError)
    {
    	nError = ERROR_SUCCESS;
    	CString strTempPath ;
    	try
    	{
    		CInternetSession Session(0, INTERNET_OPEN_TYPE_DIRECT, 0, 0, INTERNET_FLAG_DONT_CACHE);
    		
    		CHttpFile sourceFile(Session,strURL);
    		CAtlFile destFile;
    		strTempPath =  CHelperClass::SubsXMLTempPath(strPrefix);
    		HRESULT		hr = destFile.Create(strTempPath, GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
    		BYTE buffer[4096];
    		DWORD dwRead;
    
    		// Read in 4096-byte blocks,
    		// remember how many bytes were actually read,
    		// and try to write that many out. This loop ends
    		// when there are no more bytes to read.
    		int nCount = 0;
    		do
    		{
    			dwRead = sourceFile.Read(buffer, 4096);
    			if(dwRead==0 && nCount == 0)
    			{
    				nError = NO_RESULT_FROM_WEBSERVICE ; //Access Code is invalid
    				break;
    			}
    			destFile.Write(buffer, dwRead);
    			nCount++;
    		}
    		while (dwRead > 0);
    		sourceFile.Close();
    		destFile.Close();
    		Session.Close();
    	}
    	catch(CInternetException& err)
    	{
    		//ShowMessage(err.GetErrorMessage(), _T("QWE"), MB_OK ); 
    		nError = EXCEPTION_FROM_WEBSERVICE ; //Some Exception Here
    	}
    	if(nError!=ERROR_SUCCESS)
    		strTempPath.Empty();
    	return(strTempPath);
    }
    Pls let me know what wrong here.

    Thanks,
    Kapil

  2. #2
    Join Date
    Mar 2002
    Location
    Banglore
    Posts
    322

    Re: CInternetSession Caching

    Got the answer!!!

    Code:
    CHttpFile sourceFile(Session,strURL);
    shall also be defined with INTERNET_FLAG_DONT_CACHE flag

    Code:
    CHttpFile sourceFile(*pSession,strURL,0,(DWORD)-1, INTERNET_FLAG_DONT_CACHE);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured