Web service vs. Office Automation - c#

I have ASP.NET Web Service, that works under IIS.
I use Microsoft.Interop DLL to convert file from XML Table format to Excel 2003.
In my code I have reference to Microsoft.Interop DLL version 12. When I try to use this web service from VS, everything working correct.
But when I move my web service to 64-bit Windows Server 2008 I have problem with this convertion.
I place my Microsoft.Interop DLL into bin folder of my web service.
I also tried to make build for 86x and 64x platforms, but nothing changed.
Without converting my web service working correct.
What may cause this problem?

You cannot use Office Automation in a server process like a web service. It's designed to automate the Office desktop applications. In a service, it doesn't work, or causes bugs that are difficult to reproduce, is unsupported, and may even be a violation of your license with Microsoft.

Related

HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG), error, my website is on azure cloud

This error is coming when i am writing excel file thru c# code using interop from website url. It is working perfectly fine on local machine. after running publish of my website to Azure Cloud base server. It is not working on website url.
If i have to install MS Excel on Azure, how can i do that.
and
If there is any other solution, please guide me.
E_CLASSNOTREG is "Class not registered". You are likely using the Office Interop Assemblies, which require the appropriate version of Office to be installed.
If i have to install MS Excel on Azure, how can i do that.
As far as I am aware, you cannot install them for Azure web sites. You would need to use an Azure Virtual Machine to install office and get appropriate licensing. I'm not sure either if it is technically "correct" to use Office server-side from a licensing perspective.
Another option to consider is using the Open XML SDK which does not rely on Excel being installed, but may be more difficult to use. There are many other 3rd party libraries to choose from as well.

Using Interop Library for Web Server Side Excel Creation

I am trying to create excel files using interop library, but below is the error I get:
Creating an instance of the COM component with CLSID {00024500-0000-0000-
C000-000000000046} from the IClassFactory failed due to the following error: 8001010a
The message filter indicated that the application is busy.
(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)).
I looked into lots of resources out there on the net, which broadly can be categorized into following:
Interop libraries are specifically built for desktop applications, and using them in a server side web application such as wcf is highly not recommended.
Permission issues related to interactive user or DefaultAppPool.
so and and so forth.
Well, here's the caveat, I cannot change the server side application and everything works everywhere else. Few days ago, office 2016 got pushed on my machine from IT, and things stopped working (with above error) on my local machine. Now I can't go and change a legacy code, but see if I can fix the issues on my local to do further development.
Here's what I did, please note that everything was working on this machine (when office 2013 was there):
Got office 2016 Uninstalled, and re-installed office 2013, same issue, hence reverted back to office 2016. Currently MS-Office 2016 32 Bit is installed.
Verified permissions on various sections of security tab of Microsoft Excel Application, have added IIS AppPool\DefaultAppPool user, IIS_IUSRS, Interactive User with full control permission, (shouldn't the error be "Access denied", had permissions been wrong?)
Created a new sample web application, to quickly debug, ran it in all combinations of cpu platform i.e. x86, AnyCpu, x64 - same issue.
Interestingly enough, it works if I point my sample application to IIS Express instead of Local IIS.
Added latest version of interop assembly available (Install-Package Microsoft.Office.Interop.Excel -Version 15.0.4795.1000) - still same issue
Added Microsoft Office 16.0 Object Library (2.8) to the project - still same issue
It's an age old question and its probably better to get away with interop, but I wanted to understand what might be going wrong - all the direct results for the error above suggest implementing IMessageFilter or what not, but I cannot change server side code, below line should simply work as it used to few days ago:
Microsoft.Office.Interop.Excel.Application l_ExcelApp =
new Microsoft.Office.Interop.Excel.Application();
but it doesn't, so what changed? what might have gone wrong?
Also, if it helps - ApplicationID listed in dcomcnfg (/32) is : 00020812-0000-0000-C000-000000000046}, but error has a different one.
Where to look? I hope answer to this question can guide lost souls for ever about this issue.
I'd recommend using the Open XML SDK for dealing or generating open XML documents on the server-side, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just use any third-party components designed for the server-side execution.
As you already noticed, the Considerations for server-side Automation of Office article states the following:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
Finally I was able to resolve my issue. Following works:
Web Application hosted in IIS, creating excel documents.
So it turns out, apart from the permissions, it is also very important that the application architecture should be similar i.e. my application was 64bit (running as Any CPU on 64bit OS). Whenever you run into such an issue, make sure following also (apart from setting right permissions to right user):
Make sure the architecture of the two applications i.e. (your own and excel) are in sync. One quick way to know whether your excel is 64bit or 32 bit is by looking into Task Manager running programs. If excel is listed as EXECEL.EXE*32 then your office is 32 bit.
When you install a new version of excel, make sure you completely remove previous versions (and not just uninstall, but also removal of dcomconfig office entries i.e. by deleting any registry entry you can find in regedit for the involved office applications guid, specially excel).
I made it work by removing Office 2016 completely as described in 2, afterwards installing Office 2013 and fixing Microsoft.Office.Core reference accordingly in my code.
Permissions that I assigned was following:
Application Identity - Interactive User
And inside Security tab, added IIS AppPool\DefaultAppPool user to all sections and gave full permission.
My app runs in ApplicationPoolIdentity inside IIS.
If doing all the above, still doesn't fix your problem, then God be with you, and more power to you for your journey towards open XML.

ASMX file with AutoComplete not working on iis6 windows 2003 virtual server

I have an asp.net 4.0 AJAX/JQUERY Autocomplete.asmx webservice that works fine on localhost development environment. I have published the website and copied the files to the iis6 windows 2003 virtual server and then it does not work there. I have tried making a separate application under the main website and referencing the service asmx there but that does not work either. The weird thing is that I do not get an error message. I have checked the log files and I can see that the ASMX file was loaded and reference and there is no error logged there either. I am stuck at this moment. I am not sure what else to try to troubleshoot this problem. Any techniques or advice would be appreciated
The database connection was different on from the dev environment so it had to be adjusted accordingly to work from a remote server.

C++ unmanaged DLL fails to start Excel on IIS 7.5

we have a C++ Win32 DLL that reads data from Excel.
The application uses the following line to create an application:
xl.CreateInstance(L"Excel.Application");
I want to use this DLL on a .NET Project, so I've built a C++/CLI Wrapper, and reference the wrapper DLL on a C# Web Application.
Win32 (unmanaged) -> C++/CLI (managed) -> C#
The Web Application works fine on the Visual Studio integrated Web Server, however when I deploy to IIS it fails on the above line and returns the error "Invalid pointer".
I thought it could be a permissions problem so I impersonated the Web App but it didn't work. Looks like IIS does not allow open Excel from an unmanaged C++ DLL. I could open from C# but there is a lot of C++ code to read the spreadsheets and I don't want to write it again.
I am running IIS 7.5 and the applicaiton pool allow Win32 Applications.
Could you help me?
Best regards,
Using Office Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Since Windows Vista MS introduced several security-related measures which prevent a Windows Service (IIS is just a special case of that) from doing "desktop-like" things... which means you would have to circumvent several security measures (impersonation alone won't cut it!) to get it to work (NOT recommended!).
The Integrated VS web server does NOT simulate the behaviour of IIS regarding permissions etc.
To deal with Excel in a server-scenario there are several options (free and commercial) out there:
I can recommend Aspose.Cells and Flexcel... didn't try SpreadsheetGear but hear+read lots of good things about it...
Free options (though for the newer xlsx format only!) are for example OpenXML 2 from MS and EPPlus.

Open Office automation fails when executed from Web Service

I'm using this guide as a basis for what I'm doing:
http://www.codeproject.com/KB/files/generatepdf.aspx?fid=1517061&select=2903150&fr=1#xx2903150xx
I am using the Open Office CLI bridge to try to create an ASP Generic Handler that will download a file from an MS SQL database, convert it to a PDF, and send it back to the browser or app that requested it.
Here's what I've tried:
The Service shown in that article (including adding the OO.org 3 fixes).
Moving the relevant code directly into the Web Service and Switched IIS to run the 32bit .Net runtime (required for OO.org).
Creating a command line tool that performs the conversion and then spawning a process that runs the tool and waits for the Exit code (0 = success, 100 = failure a, 200 = failure b, so on and so forth)
So far all of these work when debugging the code using the development ASP server that Visual Studio provides. What doesn't work is deploying it to my development server and trying to run it there. I can get processes to run no problem, including OpenOffice's soffice.exe and soffice.bin, but under none of those circumstances does the conversion actually occur. I've tried giving the IIS service the ability to interact with the shell and trying to run the process under my own credentials (works under VS's ASP.net server but not on my dev server) but neither was fruitful.
This has been rather frustrating to be so close yet so... far. Any help figuring this one out would be appreciated. My guess is there's some IIS/ASP.net configuration option that I'm missing. My development and production environments use VS2008 and IIS6 under Windows XP 64bit.
Thanks,
Max
Have you actually installed OpenOffice on your production machine. I know that sounds big, but I have had a similar issue when dealing with MS Office. Regardless of whether I copied the appropriate files across they weren't registered.
Hence installing MS Office solved the issue. However I am sure if you register the appropriate files it would work as well. Maybe as a quick test deploy it on a machine without Open Office installed and see if it works, then install Open Office and see if

Categories