2016-08-14 6 views
0

私はボタンクリックで私のWebアプリケーションから実行したいoutlook連絡先ルックアップを持っています。次のコードは、私のdllクラスとメソッドです:Outlook Webページの連絡先を取得する - 0x800a139e - JavaScriptランタイムエラー

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("", "", "", ""); 

     }    
    } 

ボタンはWebアプリケーション上でクリックされたときに私が実行したときに、次のコードは次のとおりです。初めて

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

    var contact = al.getContact(); 
} 

オープンVS、プロセス全体が期待どおりに実行され、連絡先変数が適切なデータを返します。この問題は、ボタンをもう一度クリックするか、プロセス全体のタイムアウトを再度実行しようとするときです。

Unhandled exception at line 885, column 13 in http://localhost:27855/ScriptResource.axd?d= ... 0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out.

これまでにこれまでにやったことがないので、基本的なものが欠けているような気がします。助けてくれてありがとうございました。

予想通り(それが助け場合)Windowsアプリケーションがロードされるように私はそれを実行

+0

OutlookはCまたはC++で書かれています(afaikは完全に.Net/C#/ Managed CodeがInfoPathです)、したがって、明示的に廃棄する必要がある、またはより簡単にラップする必要があるリソースを持つunManagedライブラリを使用していますUsingステートメントで、try ... using(RDOSession session .... using(RDOAddressBook rAddressBook ...)){ –

+0

@JeremyThompson感謝、これらのオブジェクトは、RDOSessionオブジェクトに利用可能なdispose()メソッドがないため、IDisposableを実装していないようです。 –

答えて

0

私はあなたがlocalhostとこれをオフに実行している知っているが、しかし、あなたは、サーバー側のコンテキストでOfficeの自動化をやっていることをされて表示されますKB記事(Considerations for server-side Automation of Office)に従ってサポートされていません。これは、winformアプリケーションを使用して正常に動作する理由を説明します。

サーバーにOfficeをインストールするつもりはありませんでしたか?代わりに、Exchange Server WebServiceを使用して連絡先を取得するなどのサーバー側の自動化実装を行う必要があります。

編集:

"That fact has just dawned on me. This web app is for a intranet system and the dll will be registered on all the users PC's. To be able to use the users office installation with this dll would I need to run it through javascript somehow? Thanks"

JavaScriptメソッド:それはIEはActiveXのをサポートしている唯一のものである、ユーザーが任意のWebブラウザを使用することができますよう

個人的に私はthe orthodox method and use the web serviceに行くと思います。さらに、IEで動作させるには、ActiveXアクセス許可(SysAdminが上書きまたはロックダウンする可能性があります)を使用する必要があります。

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”]+”)”); 
} 

「このコードは動作しない場合は、次の操作を行います:あなたは、これは役立つはずJavascriptを経由して、それを実行したい場合は|インターネットオプション| Internet Explorerで 、[ツール]セキュリティ - >カスタム」から「レベル」に移動し、「スクリプトに安全でないとマークされていないActiveXコントロールを初期化してスクリプト化する」を選択し、「プロンプト」を選択します。

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

+0

それに感謝します。その事実がちょうど私に起こった。このWebアプリケーションはイントラネットシステム用であり、dllはすべてのユーザーPCに登録されます。このdllでユーザーのオフィスのインストールを使用できるようにするには、何とかjavascriptで実行する必要がありますか?ありがとう –

関連する問題