简体   繁体   中英

Outlook web service call

I'm trying to setup a web service that allows a user to pass me - string subject, DateTime startTime, DateTime dueDate, string body, List<string> recipients, string owner and then I create a Task . This works fine on my machine, but on Windows 2003 I keep getting different errors. Currently I'm getting - Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

I'm using an account that email access and has run on the box. I'm not sure this is the best way to do this, but it's what I got. And please be kind - I'm a .NET Web dev, not an Outlook Programmer by any stretch.

My code looks like this -

Outlook task = new Outlook();
            TaskItem taskItem = (TaskItem)_application.CreateItem(OlItemType.olTaskItem);
            taskItem.Subject = subject;
            taskItem.StartDate = startTime;
            taskItem.DueDate = dueDate;
            taskItem.Body = body;
            foreach (string recipient in recipients)
            {
                taskItem.Recipients.Add(recipient);
            }            
            taskItem.Owner = owner;
            taskItem.Assign();
            task.EntryId = taskItem.EntryID;
            if (taskItem.Saved)
            {
                task.Successful = true;
            }
            return task;

I wonder if it is a different version of office installed on the server? I have a web app that creates word documents on the server and this one time the server installed office 2003 compatability as part of group policy. Bad things happened, anyway, uninstalled it and all was good again!

These COM errors are notoriously hard to debug, and I don't know what that one means. All I can offer in the way of help is some of my own code from an existing project that does create tasks successfully in Outlook 2007. This is from a VSTO based app.

            Dim task As Outlook.TaskItem = DirectCast(Application.CreateItem(Outlook.OlItemType.olTaskItem), Outlook.TaskItem)
            task.DueDate = Date.Parse(activity.ActDate)
            task.StartDate = task.DueDate
            task.Subject = String.Format(subjectText, activity.AppID)
            task.Body = String.Format(bodyText, activity.AppID, activity.FileNum, activity.AppID)
            task.ReminderTime = Now.AddMinutes(10)
            task.ReminderSet = True
            task.Categories = CATEGORY_TEST
            task.Save()
            task.Close(OlInspectorClose.olDiscard)
            Marshal.ReleaseComObject(task)

Class ID {0006F03A-0000-0000-C000-000000000046} is the class ID of the Microsoft Office Interop assembly for Outlook which is part of the Microsoft Office PIAs . You need to install the Microsoft Office PIAs on the server before you can use .NET Office interoperability.

Here is a download link for Office 2010: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=938fe8ad-583b-4bd7-a345-23250dc15855

If you are using Visual Studio 2010 you may embed the PIAs directly in your own assembly instead of installing the PIAs on the server. To do this, locate "Embed Interop Types" in the "Properties" window for the "Microsoft.Office.Interop.Outlook" reference in VS2010 and set it to "true".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM