【问题标题】:Outlook Get Contacts for Webpage - 0x800a139e - JavaScript runtime errorOutlook 获取网页的联系人 - 0x800a139e - JavaScript 运行时错误
【发布时间】:2016-12-21 00:11:13
【问题描述】:

我有一个 Outlook 联系人查找,我想通过单击按钮从我的 Web 应用程序运行。以下代码是我的dll类和方法:

 public class AddressLookup
{
    public Contact getContact()
    {
        RDOSession session = new RDOSession();
        session.Logon(Type.Missing, Type.Missing, Type.Missing, true, Type.Missing, Type.Missing);
        bool loggedOn = session.LoggedOn;

        try
        {
            RDOAddressBook rAddressBook = session.AddressBook;
            RDORecipients rContacts = rAddressBook.ShowAddressBook(Title: "Outlook Lookup", OneAddress: true);

            RDORecipient rContact = rContacts.GetFirst();
            RDOAddressEntry aeContact = rContact.AddressEntry;

            return new Contact(aeContact.Name, aeContact.JobTitle, aeContact.CompanyName, aeContact.StreetAddress);
        }
        catch (Exception)
        {
            return new Contact("", "", "", "");

        }            
    }

以下代码是我在网络应用程序上单击按钮时运行的:

protected void btnBillHeaderDetailsOutlook_Click(object sender, EventArgs e)
{
    AddressLookup al = new AddressLookup();      

    var contact = al.getContact();
}

第一次打开VS时,整个过程按预期运行,并且contact变量返回正确的数据。这个问题是当我尝试再次单击按钮或再次运行整个 Web 应用程序时,进程超时。

http://localhost:27855/ScriptResource.axd?d= 中第 885 行第 13 列未处理的异常... 0x800a139e - JavaScript 运行时错误:Sys.WebForms.PageRequestManagerTimeoutException:服务器请求超时。

我觉得我错过了一些基本的东西,因为我以前还没有这样做过。非常感谢您的帮助。

当我将它作为 Windows 应用程序运行时,会按预期加载(如果有帮助的话)

【问题讨论】:

  • Outlook 是用 C 或 C++ 编写的(afaik 唯一完全是 .Net/C#/托管代码的办公应用程序是 InfoPath),因此您正在使用一个非托管库,其中包含您需要显式处置的资源of 甚至更容易包装在 Using 语句中,所以尝试... using(RDOSession session.... using(RDOAddressBook rAddressBook...) {
  • @JeremyThompson 谢谢,这些对象似乎没有实现 IDisposable 因为 RDOSession 对象没有可用的 dispose() 方法。

标签: c# asp.net web outlook exchange-server


【解决方案1】:

我知道您是在 localhost 之外运行此程序,但您似乎正在服务器端上下文中执行 Office 自动化,并且根据 KB 文章:Considerations for server-side Automation of Office,这是不受支持的。这可以解释为什么使用 winform 应用程序可以正常工作。

您不打算在服务器上安装 Office?相反,您应该使用 Exchange Servers WebService 来实现服务器端自动化,例如获取联系人。

编辑:

“我刚刚明白了这个事实。这个网络应用程序适用于内部网系统,并且 dll 将在所有用户 PC 上注册。为了能够使用用户办公室安装这个 dll,我需要运行它不知何故通过javascript?谢谢”

Javascript 方法:

我个人会选择the orthodox method and use the web service,因为它允许用户使用任何网络浏览器,IE 是唯一支持 ActiveX 的浏览器。除了让它在 IE 中运行之外,您可能还必须使用 ActiveX 权限(系统管理员可能会覆盖或锁定)。如果您想通过 Javascript 进行操作,这应该会有所帮助:

var Const_olFolderContacts = 10;
var objApp = new ActiveXObject(“Outlook.Application”);
var objNS = objApp.GetNamespace(“MAPI”);
var colContacts = objNS.GetDefaultFolder(Const_olFolderContacts).Items
for( var i=1; i<=colContacts.count;i++)
{
 var v = colContacts.item(i);
 alert(v[“FullName”]+” (“+v[“Email1Address”]+”)”);
}

"如果此代码不起作用,请执行以下操作: 在 Internet Explorer 中,转到工具 |互联网选项 |安全性 -> 从“自定义级别”转到“初始化并编写未标记为可安全执行脚本的 ActiveX 控件”,然后选择“提示”——现在应该可以使用了”

Wordpress blog ref.

Stackoverflow ref.

Exchange Web 服务方法:

public class MicrosoftOutlook
{
    private ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
    public MicrosoftOutlook()
    {
        try 
        {
            service.Url = new Uri("https://webmail.YourCompanyName.com.au/EWS/Exchange.asmx");

            service.UseDefaultCredentials = true;

        } catch (System.Runtime.InteropServices.COMException ex) 
        {
        }
    }

    public void ListContacts() {
    // Get the number of items in the contacts folder. To limit the size of the response, request only the TotalCount property.
    ContactsFolder contactsfolder = ContactsFolder.Bind(service, WellKnownFolderName.Contacts,  new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));

    // Set the number of items to the number of items in the Contacts folder or 50, whichever is smaller.
    int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;

    // Instantiate the item view with the number of items to retrieve from the Contacts folder.
    ItemView view = new ItemView(numItems);

    // To keep the response smaller, request only the display name.
    view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName);

    // Request the items in the Contacts folder that have the properties that you selected.
    FindItemsResults<Item>  contactItems = service.FindItems(WellKnownFolderName.Contacts, view);

    // Display the list of contacts. (Note that there can be a large number of contacts in the Contacts folder.)
        foreach (Item item in contactItems)
        {
            if (item is Contact)
            {
                Contact contact = item as Contact;
                Console.WriteLine(contact.DisplayName);
            }
        }
    }
}

参考我的代码和这个MSDN ref

【讨论】:

  • 谢谢。我刚刚明白了这个事实。此 Web 应用程序适用于 Intranet 系统,并且 dll 将在所有用户 PC 上注册。为了能够使用带有此 dll 的用户办公室安装,我需要以某种方式通过 javascript 运行它吗?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
相关资源
最近更新 更多