Tuesday, May 15, 2012

Component with CLSID XXX failed due to the following error: 80070005 Access is denied


Issue:
Component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

[5/11/2012 2:02:45 PM] Error: Excel Extraction Failed :- Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Solution:
1. In DCOMCNFG, right click on the My Computer and select properties.
2. Choose the COM Securities tab
3. In Access Permissions, click "Edit Defaults" and add Network Service to it and give it "Allow local access" permission. Do the same for <Machine_name>\Users.
4. In launch and Activation Permissions, click "Edit Defaults" and add Network Service to it and give it "Local launch" and "Local Activation" permission. Do the same for <Machine_name>\Users


Wednesday, May 9, 2012

Export To PDF

private void ExportToPDF(DataTable pdtblData)
{
byte[] bytFileData = null;
string strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".pdf";
bytFileData = GeneratePDF(pdtblData);
if(bytFileData != null)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel3, UpdatePanel3.GetType(), "scriptEF", "alert('Error Occured')", true);
}
}

Export To Excel

private void ExportToExcel(DataTable pdtblData)
{
string strFileData = string.Empty;
byte[] bytFileData = null;
string strfname = string.Empty;
strFileData = GetHTMLData(pdtblData);
strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".xls";
bytFileData = Encoding.ASCII.GetBytes(strFileData.ToString());
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}

Export To CSV

private void ExportToCSV(DataTable pdtblData)
{
string strFileData = string.Empty;
byte[] bytFileData = null;
string strfname = string.Empty;
strFileData = GetCSVData(pdtblData);
bytFileData = Encoding.ASCII.GetBytes(strFileData.ToString());
strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".csv";
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}

Export To HTML

public void ExportToHTML(DataTable pdtblData)
{
string strFileData = string.Empty;
byte[] bytFileData = null;
string strfname = string.Empty;
strFileData = GetHTMLData( pdtblData);
bytFileData = Encoding.ASCII.GetBytes(strFileData.ToString());
strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".html";
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.BinaryWrite(bytFileData);
System.Web.HttpContext.Current.Response.End();

}

There was no endpoint at XXX that could accept the message

Adding the belwo tag solved my problem of uploading the file more than 4 MB of size.

< system.web>
<httpRuntime maxRequestLength="65536" />
< /system.web>


However just for testing purpose I tried uploading file more than 20 MB of size.
The test failed :( and the new exception I got was

"There was no endpoint at XXX that could accept the message. This is often caused by an incorrect address or SOAP action"

My Service bindings was as below

<binding name="My_Binding" closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"
    textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
     <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
     <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
     <security mode="Message">
      <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
      <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
     </security>
    </binding>


Also I had <httpRuntime maxRequestLength="65536" /> in web.config

Googling through several article, finally I found a solution. Adding the below tag in my WCF Service help me to upload document more than 20 MB of size

<system.webServer>  
     <security>    
           <requestFiltering>
                    <requestLimits maxAllowedContentLength="204800000" />    
          </requestFiltering>  
   </security>
</system.webServer> 



An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel.

I was getting an error "An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel." when I was trying to upload / stream large file through WCF Service, the file I was using is of more than 4 MB.

When we sent small files through the service, all worked fine. However, larger files (about 4MB and higher) generated the very unhelpful http exception: (400) Bad Request. This exception occurs because the entire message is not processed.

We looked at the typical culprits of this problem like <binding> settings such as maxReceivedMessageSize and <readerQuota> values to no avail.
It turned out the real problem was not in WCF, but in IIS. HTTP communication has a size limit that you have to override if you want to send large messages to your WCF service hosted in IIS. In the config file (web.config), adjust the <httpRuntime>‘s maxRequestLength attribute to a large enough size to support your messages. The value will be an integer representing the size in Kilobytes and has about a 2GB limit. The setting looks something like this (I set mine to about 64MB):
< system.web>
       <httpRuntime maxRequestLength="65536" />
< /system.web>

If IIS is the problem, you should now be able to process messages up to the size indicated in the maxRequestLength attribute.