NEWBIE: How to do this in C#?

T

Terry-OMAF

I'm trying to create a web service in C# to populate a drop down in MS
InfoPath with Active Directory users. How do I return what's found (if
possble please provide code)?

I've started the code but not sure how to finish it. Specifically the
getAdUsers method.

=======================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.DirectoryServices;


namespace getUserInfo_June10_Ver1
{
/// <summary>
/// Summary description for Service1.
/// </summary>

[WebService(Namespace="http://www.on.ca")]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion

[WebMethod]
public ???? getAdUsers()
{
DirectoryEntry entryAllUsers = new
DirectoryEntry("LDAP://ou=people,ou=peeps,dc=gov,dc=on,dc=ca");
DirectorySearcher dsAllUsers = new DirectorySearcher(entryAllUsers);
string [] strAttrs = new
string[]{"givenName","sn","mail","telephoneNumber"};
dsAllUsers.Filter = "(objectClass=user)";
dsAllUsers.PropertiesToLoad.AddRange(strAttrs);
return ???????;
}
}
}
 
D

DKode

I would probably create an ArrayList containing string arrays in your
method getAdUserss() and return the ArrayList containing the
information you want to return.

you'll have to put in a foreach loop to iterate through the
DirectorySearcher object (dsAllUsers) each iteration, making a string
array, adding the values (giveName, sn, mail, telephoneNumber) and then
adding it to the ArrayList.

Might be a more effecient way to do this, but at first glance thats
what my gut tells me.
 
W

www.VoiceInformation.com

Web Methods C# SAP


Terry -

Attached is some C# code that may help point you in the right
direction.

We use a webmethods call to get the latest product version number and a
list of sponsors from our main website (ex:
http://www.vinfo.com/Updates/TGPlugIn/ProductInfo.asmx).

We use the same code for both our TekGuard Mail Server product and our
Outlook anti-spam plugin. You can download the source code listed below
from www.TekGuard.com. This will let you see how it is used in context
with the .asmx file.


<snippet>

#region TGPCheckUpdates
public void TGPCheckUpdates ()
{
// Already Checking?
if (m_thrChecking != null) return;

// Have we checked in the past week since startup?
if (!m_bCheckUpdates || (m_dtLastCheck.AddDays(VER_CHECKWEEKLY) >
DateTime.Now)) return;

// Create a new thread for the WebMethods call
m_thrChecking = new Thread(new
ThreadStart(TGPCheckUpdates_Thread));
m_thrChecking.Priority = ThreadPriority.Lowest;
m_thrChecking.IsBackground = true;
m_thrChecking.Start();
}
private void TGPCheckUpdates_Thread()
{
string NewVersion;
string[] Sponsors;

// Connect to VISI web service
// Note: This is done without sending any information about your
computer
if (CheckUpdates_WebMethod(out NewVersion, out Sponsors))
{
// Success - save last version check date
m_dtLastCheck = DateTime.Now;

// Update Sponsors list
m_PlugIn.Sponsors = Sponsors;

// New version available?
if (NewVersion != null) m_PlugIn.LogAlert("Start", "A newer
version (" + NewVersion + ") is available", null);
}

// Done checking
m_thrChecking = null;
}
private bool CheckUpdates_WebMethod (out string NewVersion, out
string[] Sponsors)
{
try
{
// Get VISI Product info using WebMethods call
ProductInfo Info = new ProductInfo();

// Set the timeout to be relaively short
Info.Timeout = WEB_TIMEOUT;

// Get this local (running) version
string ThisVersion =
Assembly.GetExecutingAssembly().GetName().Version.ToString();

// Future: Use split command to compare embedded values
string CurrentVersion = Info.getVersion();

// Return version status
NewVersion = (CurrentVersion.CompareTo(ThisVersion) > 0) ?
Info.getVersion() : null;

// Return sponsor list
Sponsors = Info.getSponsors();

// Success
return (true);
}
catch
{
// Assume no updates available if info not available
NewVersion = null;
Sponsors = null;
return (false);
}
}
#endregion


</snippet>


Posted by www.AndrewM.com [PostID 20050621]

Software Entrepreneurs, ISV's, Developers - Sell & Support your
programs with an 800# virtual auto-attendant:
www.VoiceInfo.com - <a href="http://www.VoiceInfo.com">
Virtual Office, Automated Phone Assistant, Web Access </a><br>

Developers, ISP's, Small Business Owners - Need a starting point
for an anti-spam email server, Outlook client, WebMail?
www.TekGuard.com - <a href="http://www.TekGuard.com">
Free Mail Server, Outlook PlugIn, WebMail, C# Source Code </a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top