2010-02-09 8 views
5

मैं ईडब्ल्यूएस का उपयोग कर रहा हूं और कंपनी के आदान-प्रदान से वैश्विक पता सूची प्राप्त करना चाहता हूं। मुझे पता है कि व्यक्तिगत संपर्क सूची कैसे प्राप्त करें।मैं एक्सचेंज वेब सर्विसेज (ईडब्ल्यूएस) के साथ वैश्विक संपर्क कैसे प्राप्त करूं?

एपीआई दस्तावेज में सभी नमूने उपयोगकर्ता की जानकारी अपडेट करने के साथ सौदा करते हैं लेकिन विशेष रूप से उन्हें कैसे पुनर्प्राप्त नहीं करते हैं।

मैंने फ़ोल्डर्स को सूचीबद्ध करने के लिए निम्नलिखित कोशिश भी की है लेकिन यह सही परिणामों को कम नहीं करता है।

private static void ListFolder(ExchangeService svc, FolderId parent, int depth) { 
    string s; 
    foreach (var v in svc.FindFolders(parent, new FolderView(int.MaxValue))) { 
     Folder f = v as Folder; 
     if (f != null) { 
      s = String.Format("[{0}]", f.DisplayName); 
      Console.WriteLine(s.PadLeft(s.Length + (depth * 2))); 
      ListFolder(svc, f.Id, depth + 1); 

      try { 
       foreach (Item i in f.FindItems(new ItemView(20))) { 
        Console.WriteLine(
         i.Subject.PadLeft(i.Subject.Length + ((depth + 1) * 2))); 
       } 
      } catch (Exception) { 
      } 
     } 
    } 
} 

सवाल पहले से ही EWS का उपयोग कर वैश्विक पता सूची प्राप्त करने के लिए, जबकि इस सवाल का एक सामान्य स्तर पर सलाह के लिए पूछता है के साथ विशेष रूप से (How to get contact list from Exchange Server?) इस सवाल सौदों उठाया गया है।

उत्तर

2

आप कर सकते हैं मिल गया itemtype नीचे कोड स्निपेट के साथ एक specifiedfolder में वस्तुओं और फिर itemtype ContactItemType को वस्तुओं (संपर्क वस्तुओं के लिए) डाली ....

/// <summary> 
    /// gets list of ItemType objects with maxreturncriteria specicification 
    /// </summary> 
    /// <param name="esb">ExchangeServiceBinding object</param> 
    /// <param name="folder">FolderIdType to get items inside</param> 
    /// <param name="maxEntriesReturned">the max count of items to return</param> 
    public static List<ItemType> FindItems(ExchangeServiceBinding esb, FolderIdType folder, int maxEntriesReturned) 
    { 
     List<ItemType> returnItems = new List<ItemType>(); 
     // Form the FindItem request 
     FindItemType request = new FindItemType(); 
     request.Traversal = ItemQueryTraversalType.Shallow; 
     request.ItemShape = new ItemResponseShapeType(); 
     request.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; 
     request.ParentFolderIds = new FolderIdType[] { folder }; 
     IndexedPageViewType indexedPageView = new IndexedPageViewType(); 
     indexedPageView.BasePoint = IndexBasePointType.Beginning; 
     indexedPageView.Offset = 0; 
     indexedPageView.MaxEntriesReturned = 100; 
     indexedPageView.MaxEntriesReturnedSpecified = true; 
     request.Item = indexedPageView; 
     FindItemResponseType response = esb.FindItem(request); 
     foreach (FindItemResponseMessageType firmtMessage in response.ResponseMessages.Items) 
     { 
      if (firmtMessage.ResponseClass == ResponseClassType.Success) 
      { 
       if (firmtMessage.RootFolder.TotalItemsInView > 0) 
        foreach (ItemType item in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items) 
         returnItems.Add(item); 
         //Console.WriteLine(item.GetType().Name + ": " + item.Subject + ", " + item.DateTimeReceived.Date.ToString("dd/MM/yyyy")); 
      } 
      else 
      { 
      //handle error log here 
      } 
     } 
     return returnItems; 
    } 
+0

+1 क्योंकि आप वास्तव में जवाब दे रहे हैं उसकी सवाल। हालांकि सिर्फ फिर से पुन: प्रयास करना चाहता था कि यह केवल उन उपयोगकर्ताओं को पकड़ लेगा जिनके पास एक्सचेंज में मेलबॉक्स हैं जो एडी में उपयोगकर्ताओं का सबसेट है। –

+0

मुझे नहीं पता कि यह सवाल का जवाब कैसे देता है? ब्रेट का उल्लेख है कि वह जानता है कि इस जानकारी को किसी विशिष्ट फ़ोल्डर (संपर्क) के लिए कैसे खींचें, लेकिन वैश्विक पता सूची के लिए इसे कैसे करें। – Miles

0

मैं सिर्फ एक समान काम किया। हालांकि, मैं एक्सचेंज के माध्यम से संपर्कों की सूची प्राप्त करने में असमर्थ था क्योंकि केवल उन उपयोगकर्ताओं को प्राप्त होता है जिनमें मेलबॉक्स हैं, और आवश्यक रूप से सभी उपयोगकर्ता या समूह नहीं हैं। अंत में मैं सभी उपयोगकर्ताओं को एडी

के माध्यम से सभी उपयोगकर्ताओं को प्राप्त करने के लिए समाप्त हो गया है। आपको केवल वैश्विक पता सूची का फ़ोल्डर आईडी है जिसे आपके एडी सर्वर पर ADSI.msc टूल का उपयोग करने और वैश्विक पता सूची फ़ोल्डर में ब्राउज़ करने, गुणों को देखने और "शुद्ध खोज" के मूल्य को पकड़ने के लिए प्राप्त किया जा सकता है। अपने सिस्टम में वैश्विक पता सूची के लिए searchPath है "(& (objectClass = user) (objectCategory = व्यक्ति) (mailNickname = ) (msExchHomeServerName =))"

public List<ListItem> SearchAD(string keyword, XmlDocument valueXml) 
    {   
     List<ListItem> ewsItems = new List<ListItem>(); 

     using (DirectoryEntry ad = Utils.GetNewDirectoryEntry("LDAP://yourdomain.com")) 
     { 
      Trace.Info("searcherをつくる"); 
      using (DirectorySearcher searcher = new DirectorySearcher(ad)) 
      { 
       if (this.EnableSizeLimit) 
       {   
        searcher.SizeLimit = GetMaxResultCount(); 

        if (Utils.maxResultsCount > 1000) 
        { 
         searcher.PageSize = 100; 
        } 
       } 
       else 
       { 
        searcher.SizeLimit = 1000; 
        searcher.PageSize = 10; 
       } 

       string sisya = Utils.DecodeXml(valueXml.SelectSingleNode("Folder/SearchPath").InnerText); //this is the folder to grab your contacts from. In your case Global Address list 

       //Container 
       if(String.IsNullOrEmpty(sisya)) 
       { 
        return null; 
       } 

       keyword = Utils.EncodeLdap(keyword); 

       string text = Utils.DecodeXml(valueXml.SelectSingleNode("Folder/Text").InnerText); 

       searcher.Filter = this.CreateFilter(keyword, sisya); 
       searcher.Sort = new SortOption("DisplayName", System.DirectoryServices.SortDirection.Ascending); 

       //一つのPropertyをロードすると、全Propertyを取らないようになる 
       searcher.PropertiesToLoad.Add("SAMAccountName"); //どのPropertyでもいい。 


       SearchResultCollection searchResults = searcher.FindAll(); 



       foreach (SearchResult searchResult in searchResults) 
       { 
        //ListItem contact = null; 
        using (DirectoryEntry userEntry = searchResult.GetDirectoryEntry()) 
        { 
         try 
         { 
          string schemaClassName = userEntry.SchemaClassName; 
          switch (schemaClassName) 
          { 
           case "user": 
           case "contact": 
            string fname = userEntry.Properties["GivenName"].Value == null ? "" : userEntry.Properties["GivenName"].Value.ToString(); 
            string lname = userEntry.Properties["sn"].Value == null ? "" : userEntry.Properties["sn"].Value.ToString(); 
            string dname = userEntry.Properties["DisplayName"][0] == null ? lname + " " + fname : userEntry.Properties["DisplayName"][0].ToString(); 

            //No Mail address 
            if ((userEntry.Properties["mail"] != null) && (userEntry.Properties["mail"].Count > 0)) 
            { 


             string sAMAccountName = ""; 
             if(userEntry.Properties["SAMAccountName"].Value != null){ 
              sAMAccountName = userEntry.Properties["SAMAccountName"].Value.ToString(); 
             } 
             else{ 
              sAMAccountName = userEntry.Properties["cn"].Value.ToString(); 
             } 
             string contactXml = Utils.ListViewXml(sAMAccountName, UserType.User, Utils.UserXml(fname, lname, userEntry.Properties["mail"].Value.ToString(), dname, null), ServerType.Ad); 
             ewsItems.Add(new ListItem(dname + "<" + userEntry.Properties["mail"].Value.ToString() + ">", contactXml)); 
            } 
            else 
            { 
             ListItem contact = new ListItem(dname, null); 
             contact.Enabled = false; 

             ewsItems.Add(contact); 

             Trace.Info("追加できないユーザ: " + searchResult.Path); 
            } 
            break; 
           case "group": 
            ewsItems.Add(new ListItem(userEntry.Properties["DisplayName"].Value.ToString(), Utils.ListViewXml(userEntry.Properties["SAMAccountName"].Value.ToString(), UserType.Group, null, ServerType.Ad))); 
            break; 
           default: 
            userEntry.Properties["SAMAccountName"].Value.ToString()); 
            ewsItems.Add(new ListItem(userEntry.Properties["name"].Value.ToString(), Utils.ListViewXml(userEntry.Properties["SAMAccountName"].Value.ToString(), UserType.Group, null, ServerType.Ad))); 
            break; 

          } 
         } 
         catch (Exception ex) 
         { 
          Trace.Error("User data取得失敗", ex); 
         } 
        } 
       } 

       searchResults.Dispose(); 

      } 
     }  
     return ewsItems; 
    } 
संबंधित मुद्दे