Hello everyone,
i have a problem with a ConsoleApplication which I am actually writing for FIM CM. The problem appears with or without .Net remoting I tested both.
The problem appears at this little piece of code:
public static ReadOnlyCollection<ProfileTemplate> FindAllProfileTemplates(FindOperationsByCulture findOperationsByCulture)
{
FindOperations.UseRemoting = true;
return findOperationsByCulture.FindAllProfileTemplates(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture);
}
And in my main method I am calling the function like this:
ReadOnlyCollection<ProfileTemplate> templates = FindAllProfileTemplates(findOperationsByCulture);
Which leads to the Exception mentioned in the title:
Unhandled Exception: System.InvalidCastException: Return argument has an invalid
type.
at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(Object arg, Ty
pe paramType)
at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(IMessage
msg, Object[] outArgs, Object returnValue)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at Microsoft.Clm.Provision.FindOperationsByCulture.FindAllProfileTemplates(Cu
ltureInfo uiCulture, CultureInfo culture)
Can anybody explain me what am I doing wrong? I took the PowerShell example from Craig Martin (http://www.integrationtrench.com/2010/11/use-fim-cm-provision-api-from.html) and in PowerShell everything works like a charm. I do the same (but ajdusted it for C#) and i get this exception.
I post the whole Code of the program here, so maybe the Problem is in another place of the code.
Every help is highly appreciated :-)
Thank you very much!
Tom
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Clm;
using Microsoft.Clm.Common;
using Microsoft.Clm.Common.Requests;
using Microsoft.Clm.Common.TypedData;
using Microsoft.Clm.Provision;
using ProvisionApiRequests = Microsoft.Clm.Shared.Requests;
using Microsoft.Clm.Shared.ProfileTemplates;
using Microsoft.Clm.Shared.Profiles;
using Microsoft.Clm.BusinessLayer.SmartCard.BaseCsp;
using System.Runtime.Remoting;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Remoting.Channels;
using System.Collections;
using System.Runtime.Remoting.Channels.Http;
using System.Net;
using System.Globalization;
namespace ConsoleApplication1
{
class Program : MarshalByRefObject
{
public static ReadOnlyCollection<ProfileTemplate> FindAllProfileTemplates(FindOperationsByCulture findOperationsByCulture)
{
FindOperations.UseRemoting = true;
return findOperationsByCulture.FindAllProfileTemplates(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture);
}
static void Main(string[] args)
{
string path = Directory.GetCurrentDirectory();
RemotingConfiguration.Configure(path+@"\app.config", true);
BinaryClientFormatterSinkProvider binaryClientFormatterSinkProvider = new BinaryClientFormatterSinkProvider();
HttpClientChannel httpClientChannel = new HttpClientChannel("ClmHttpChannel", binaryClientFormatterSinkProvider);
ChannelServices.RegisterChannel(httpClientChannel, true);
FindOperationsByCulture findOperationsByCulture = new FindOperationsByCulture();
var channelProperties = ChannelServices.GetChannelSinkProperties(findOperationsByCulture);
Uri clmUri = new Uri(RemotingServices.Marshal(findOperationsByCulture).URI);
NetworkCredential networkCredentials = new NetworkCredential("administrator", "Password1", "stind");
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(clmUri, "ntlm", networkCredentials);
channelProperties["credentials"] = credentialCache;
ReadOnlyCollection<ProfileTemplate> templates = FindAllProfileTemplates(findOperationsByCulture);
}
}
}