COM Automation and the complexe Data Type

HediHedi Member Posts: 16
edited 2010-06-01 in NAV Three Tier
Hi All,

Im developping a COM Automation class that implement some Methodes using simple Data type like String ,Int, Float,...

But I Have a probleme to use the complexe data. For exemple if I have a Methode that return an Object of a specific class type haw can I do it, haw Nav can see and know this complexe type and the attributes declared as public.

the following is my exemple:

public interface ITarifCRM
{
bool CreationTarif(string CodeTarif, string Nom, bool OffreConventionne);
OffreResponseInfo CreationTarif2(string CodeTarif, string Nom, bool OffreConventionne);
}

[ComVisible(true)]
[Guid("83ec5c0b-c8b8-416f-9003-fd23bbb850f7")]
[ComSourceInterfaces(typeof(ITarifCRM))]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class TarifCRM:ITarifCRM
{
public ServiceOffreClient Serviceoffclient;
public ServiceTarif.IServiceOffre IServiceoffre;
public OffreResponseInfo info;
private string ServiceUrl="net.[url=tcp://192.168.231.184:8733/TopnetWcfServiceLibrary/ServiceOffre/]tcp://192.168.231.184:8733/TopnetWcfSer ... viceOffre/[/url]";

public bool CreationTarif(string CodeTarif,string Nom,bool OffreConventionne)
{
EndpointAddress ead = new EndpointAddress(ServiceUrl);

NetTcpBinding tcpbd = new NetTcpBinding();

ChannelFactory<ServiceTarif.IServiceOffre> factory = new ChannelFactory<IServiceOffre>(tcpbd, ead);
factory.Credentials.Windows.AllowedImpersonationLevel
System.Security.Principal.TokenImpersonationLevel.Impersonation;
factory.Credentials.Windows.ClientCredential.Domain = "MACHINE-TEST";
factory.Credentials.Windows.ClientCredential.UserName = "administrateur";
factory.Credentials.Windows.ClientCredential.Password = "M%test6";


IServiceOffre chanel = factory.CreateChannel();





Tarif T = new Tarif();
T.Nom = Nom;
T.CodeTarif = CodeTarif;
T.OffreConventionne = OffreConventionne;

ServiceTarif.OffreResponseInfo respInfo;

respInfo = chanel.CreationTarif(Origine.Billing, T);


if (respInfo.Code == 0)
return true;
else
return false;

}

public OffreResponseInfo CreationTarif2(string CodeTarif, string Nom, bool OffreConventionne)
{
EndpointAddress ead = new EndpointAddress(ServiceUrl);

NetTcpBinding tcpbd = new NetTcpBinding();

ChannelFactory<ServiceTarif.IServiceOffre> factory = new ChannelFactory<IServiceOffre>(tcpbd, ead);
factory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
factory.Credentials.Windows.ClientCredential.Domain = "MACHINE-TEST";
factory.Credentials.Windows.ClientCredential.UserName = "administrateur";
factory.Credentials.Windows.ClientCredential.Password = "M%test6";
IServiceOffre chanel = factory.CreateChannel();
Tarif T = new Tarif();
T.Nom = Nom;
T.CodeTarif = CodeTarif;
T.OffreConventionne = OffreConventionne;

ServiceTarif.OffreResponseInfo respInfo;

respInfo = chanel.CreationTarif(Origine.Billing, T);
return (OffreResponseInfo)respInfo;
}
}


the first Methode "bool CreationTarif" return a simple type that NAV can use it and understand.
the second Methode "OffreResponseInfo CreationTarif2" return an object with some properties. NAV canot understand this complexe type. Haw can I enable it as portable to NAV from the COM Interface and the implementation.


Thax for Help.

Comments

  • PhilThomePhilThome Member Posts: 5
    Hi Hedi,

    you have to make the class OffreResponseInfo an automation, too. You can then declare a variable in NAV of that type. And use that variable to store the return object of the method CreationTarif2. Let's say ori is the name of the variable of type OffreResponseInfo and tarifCRM a variable of type TarifCRM.
    IF CREATE(tarfiCRM) THEN 
        ori := tarifCRM.CreationTarif2([...]);
    

    That should work. But it might be better to use ori as a out parameter using the return value for error handling. You'd then had an interface like this (some might prefer an integer as error code):
    string CreationTarif2(string CodeTarif, string Nom, bool OffreConventionne, out OffreResponseInfo);
    

    In NAV you'd use it like this:
    IF CREATE(tarfiCRM) AND CREATE(ori) THEN 
    BEGIN
        errorString := tarifCRM.CreationTarif2([...], ori);
        IF errorString <> '' THEN
            ERROR(errorString);
    END;
    

    Before SP1 it should work without creating the "ori"-object first. But there's some strange behaviour when using the RTC and complex parameters since SP1. It might be necessary to use "Object" instead of "OffreResponseInfo" as parameter type and a cast in .NET to make it work.
    You should cut the errorString to a length NAV can handle, by the way.
  • ferrysbferrysb Member Posts: 14
    Hi All,

    I have a question related with this topic, please help, I'm creating the automation with return value = DataTable. How can I retrieve it on Navision ?
    If can't, is there any work around for sending datatable from C# automation to Navision ?

    Many thanks,
    Ferry
  • Christian_AbelnChristian_Abeln Member, Microsoft Employee Posts: 42
    No, a .NET DataTable does not provide a COM object interface which you could expose to AL.

    You could nevertheless make a COM object that saves the DataTable into XML and return this to AL instead. Then use a matching XML Port in AL to import the data into a table.
    “This posting is provided "AS IS" with no warranties, and confers no rights.”

    Christian Abeln
    Program Manager Microsoft
    Dynamics NAV

    blogs.msdn.com/cabeln/
Sign In or Register to comment.