----- this issue was solved, doesn't relate to subject see explanation at bottom -----
I've put together a C# dll that I'm running as a COM object to handle Exchange Server processing. One of functions it performs creates a users mailbox. I've set up a COM+ application so it's running as an Exchange Administrator.
When CreateObject in VBScript and call the function, it works. When I do the same thing in an ASP page (using Server.CreateObject) it does nothing.
Any ideas as to what different behaviors I should be looking for between VBscript and ASP Classic in this case?
The DLL code being executed:
public void CreateMailbox(String database, String dc, String upn)
{
String retval = String.Empty;
Dictionary<String, object> args = new Dictionary<string, object>();
args.Add("Identity", upn);
args.Add("Database", database);
args.Add("DomainController", dc);
Collection<PSObject> result = ExecuteCmdlet("Enable-Mailbox", args);
return;
}
And ExecuteCmdlet
private Collection<PSObject> ExecuteCmdlet(String cmdlet, Dictionary<String,object> arguments)
{
RunspaceConfiguration rsConf = RunspaceConfiguration.Create();
PSSnapInException psException = null;
PSSnapInInfo psInfo = rsConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out psException);
Runspace rs = RunspaceFactory.CreateRunspace(rsConf);
rs.Open();
Pipeline pipe = rs.CreatePipeline();
Command psCmd = new Command(cmdlet);
foreach (KeyValuePair<String,object> arg in arguments)
{
psCmd.Parameters.Add(arg.Key, arg.Value);
}
pipe.Commands.Add(psCmd);
Collection<PSObject> retVal = pipe.Invoke();
rs.Close();
return retVal;
}
EDIT: This seems to be an issue with my ASP implementation, which involves me trying to tie it into a 3rd party AD management tool. When I use the code in a stand alone ASP page, it works. Seems like this requires some more research on my part.
EDIT2: A couple hours of research hasn't yielded anything on the way IIS handles COM+ objects that have a bound identity in any way indicating the problem. The VBS requested is below. This works. This exact same code works in an ASP Classic web page. When I run this exact same code in a different web app in the same vdir, it fails to create the mailbox. The app in question is a MVC front end to Active Directory written in ASP Classic.
Dim exch
Set exch = CreateObject("ExchangeMailboxCreator.ExchangeMailboxBuilder")
exch.CreateMailbox("Mailbox\SG\DB", "domaincontroller.domain.com", "TestUserAccount")
FINAL EDIT: Unsurprisingly, this was an issue not with the above code, but with the code around it. The application I was integrating with was using AD LDS as a staging directory before periodically writing back to AD. This meant my attempts to directly touch Exchange were failing because the AD account didn't exist. I hacked my way around it by adding a loop to sleep until the Exchange environment recognized the user existed. Not... my favorite solution ever, but I'll take it. Thanks for all the suggestions.