COM Automation and the complexe Data Type

Hedi
Member Posts: 16
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.
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.
0
Comments
-
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.0 -
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,
Ferry0 -
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/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions