Passing credentials to ExportCatalog.exe?

I'm trying to export the product catalog from our production catalog using the URL of the web service. For security reasons, we've locked down the web service web site to require windows authentication and the production server is in a different domain.

Can someone tell me how i can pass the proper credentials to the command line application?

thanks,
Michael.

[377 byte] By [michaelaird] at [2008-1-8]
# 1

Michael,

I've marked the important lines in red, basically, there's nothing in the code which sets the "Credentials" property on the CatalogServiceAgent, which you would need in order to accomplish what you're doing. Otherwise, this application will just run as the identity of the currently logged in user (who is likely not authenticated on the other domain).

Looking under the hood, we find (thanks to Lutz Roeder's Reflector):

Code Snippet

public static void Main(string[] args)
{
bool flag = false;
try
{
Options options = new Options();
CatalogExportOptions options2 = new CatalogExportOptions();
options.AcceptableBinaryOptions.AddRange(AcceptableBinaryOptions);
options.AcceptableUnaryOptions.AddRange(AcceptableUnaryOptions);
try
{
options.ProcessArgs(args);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
return;
}
string text = null;
string text2 = null;
if (options.HasUnaryOption("Debug"))
{
flag = true;
}
if (options.HasUnaryOption("?") || (args.Length == 0))
{
PrintUsage();
}
else
{
CatalogContext context;
if (options.HasBinaryOption("Site"))
{
text2 = options["site"];
}
else if (options.HasBinaryOption("S"))
{
text2 = options["s"];
}
else if (options.HasBinaryOption("W"))
{
text = options["w"];
}
else if (options.HasBinaryOption("WebService"))
{
text = options["webservice"];
}
else
{
Console.WriteLine("You must specify a URL for web service");
PrintUsage();
return;
}
if (text != null)
{
Console.WriteLine("Connecting to web service {0}", text);
CatalogServiceAgent agent = new CatalogServiceAgent(text);
context = CatalogContext.Create(agent);
}
else
{
if (text2 == null)
{
Console.WriteLine("You must specify a site name");
return;
}
Console.WriteLine("Connecting to site {0}", text2);
CatalogSiteAgent agent2 = new CatalogSiteAgent();
agent2.set_SiteName(text2);
if (options.HasBinaryOption("AzMan"))
{
string text3 = options["AzMan"];
if (flag)
{
Console.WriteLine("Using AzMan policy: {0}", text3);
}
agent2.set_AuthorizationMode(3);
agent2.set_AuthorizationPolicyPath(string.Format("{0}", text3));
}
else
{
agent2.set_AuthorizationMode(1);
}
context = CatalogContext.Create(agent2);
}
options2.set_CatalogsToExport(options.GetBinaryOption("Catalogs", options2.get_CatalogsToExport()));
options2.set_ExportAsVirtualCatalog(!options.HasUnaryOption("VCasBC"));
options2.set_SchemaExportType(options.GetEnum<SchemaExportType>("Schema", 1));
options2.set_Descendants(options.GetEnum<Descendants>("Descendants", 0));
options2.set_ExportEmptyValues(options.HasUnaryOption("EmptyValues"));
options2.set_Language(options.GetBinaryOption("Language", options2.get_Language()));
options2.set_Namespace(options.GetBinaryOption("Namespace", options2.get_Namespace()));
options2.set_ExportDependentBaseCatalogs(options.HasUnaryOption("ExportDependentCatalogs"));
options2.set_ExportDeletedItems(options.HasUnaryOption("ExportDeletedItems"));
options2.set_CatalogSetsToExport(options.GetBinaryOption("CatalogSetsToExport", options2.get_CatalogSetsToExport()));
if (options.HasBinaryOption("ProductsAndCategories"))
{
options2.set_ProductsAndCategoriesClause(options["ProductsAndCategories"]);
options2.set_Mode(1);
}
if (options.HasBinaryOption("FilterDescendants"))
{
if (string.IsNullOrEmpty(options2.get_ProductsAndCategoriesClause()))
{
throw new Exception("Invalid options. FilterDescendants cannot be specified without ProductsAndCategories");
}
options2.set_FilterDescendantsClause(options["FilterDescendants"]);
options2.set_Mode(1);
}
options2.set_PropertiesToExport(options.GetBinaryOption("PropertiesToExport", options2.get_PropertiesToExport()));
if (options.HasUnaryOption("Xsd"))
{
options2.set_FormatType(1);
}
options2.set_Synchronous(true);
if (flag)
{
Console.WriteLine("CatalogSetsToExport: {0}", options2.get_CatalogSetsToExport());
Console.WriteLine("CatalogsToExport: {0}", options2.get_CatalogsToExport());
Console.WriteLine("Descendants: {0}", options2.get_Descendants());
Console.WriteLine("ExportAsVirtualCatalog: {0}", options2.get_ExportAsVirtualCatalog());
Console.WriteLine("ExportDeletedItems: {0}", options2.get_ExportDeletedItems());
Console.WriteLine("ExportDependentBaseCatalogs: {0}", options2.get_ExportDependentBaseCatalogs());
Console.WriteLine("ExportEmptyValues: {0}", options2.get_ExportEmptyValues());
Console.WriteLine("FilterDescendantsClause: {0}", options2.get_FilterDescendantsClause());
Console.WriteLine("FormatType: {0}", options2.get_FormatType());
Console.WriteLine("Language: {0}", options2.get_Language());
Console.WriteLine("Mode: {0}", options2.get_Mode());
Console.WriteLine("Namespace: {0}", options2.get_Namespace());
Console.WriteLine("ProductsAndCategoriesClause: {0}", options2.get_ProductsAndCategoriesClause());
Console.WriteLine("PropertiesToExport: {0}", options2.get_PropertiesToExport());
Console.WriteLine("SchemaExportType: {0}", options2.get_SchemaExportType());
}
string[] nakedParameters = options.GetNakedParameters();
if ((nakedParameters != null) && (nakedParameters.Length == 1))
{
string text4 = nakedParameters[0];
options2.set_Synchronous(false);
Console.WriteLine("Exporting to {0}", text4);
ExportProgress progress = context.ExportXml(options2, text4);
DateTime now = DateTime.Now;
int millisecondsTimeout = 500;
while (progress.get_Status() == null)
{
DateTime time2 = DateTime.Now;
TimeSpan span = new TimeSpan(time2.Ticks - now.Ticks);
Console.CursorLeft = 0;
Console.Write("{1:0000}:{2:00} Exporting {0}% complete", progress.get_PercentComplete(), span.TotalMinutes, span.Seconds);
Thread.Sleep(millisecondsTimeout);
progress.Refresh();
if (millisecondsTimeout < 0x1388)
{
millisecondsTimeout += 500;
}
}
progress.Refresh();
Console.WriteLine();
Console.WriteLine("Completed: {0}", progress.get_Status().ToString("G"));
foreach (OperationErrorsDataSet.OperationError error in progress.get_Errors().get_DataSet().get_OperationErrors())
{
Console.WriteLine("Error: {0}({1}): {2}", text4, error.get_LineNumber(), error.get_Message());
}
}
}
}
catch (Exception exception2)
{
if (flag)
{
Console.WriteLine(exception2.ToString());
}
else
{
Console.WriteLine(exception2.Message);
}
}
}

Here's the documentation on the Credentials property:

http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.serviceagent.credentials.aspx

You should be able to write your own ExportCatalog tool pretty easily by using Roeder's reflector on the existing tool and just swiping Microsoft's code. Just add username and password parameter to create the credentials and you should be good to go!

JosephJohnson at 2007-10-2 > top of Msdn Tech,Commerce Server,Commerce Server 2007...