All -
I'm a .Net programmer at heart, so I can't resist the opportunity to get back into my roots

I've written a .Net assembly that logs onto and streams XML data to one of our partner company's web sites. It then waits for a response, and parses the response xml to determine if the data was accepted. I've tested the assembly using a test form in the .Net IDE, and all is well there.
I've regasm'd it with the /tlb and /codebase switches, and I am able to create an automation variable with no issue in Navision.
What I haven't quite figured out is the WithEvents property for a global. I've set it to "Yes", which I thought would cause the events from my assembly to appear as triggers in my codeunit, but I'm not seeing them. Am I missing something? Will Navision handle events from a .Net assembly?
Thanks.
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
You need to create a seperate interface for the events and then implement that interface by using
[ComSourceInterfaces(interfacename)]
If you find a solution? Could you share how you've cracked it?
Obviously you have been able to stream to a .net dll (I'm currently fighting with that, maybe you can have a look at this, that would be very nice
chrido - I wasn't planning on passing a stream from Navision to .Net, or vice versa (although it would be useful - oh how I wish I could save Navision reports to a stream - I'd just splat it into a memory stream)- I'm just passing the data (as an string) to the dll and waiting on the response. When i get the response, i'm raising one of a few events indicating what the results were, and whether I got my ID from the remote system (it's an ASN system).
As I indicated before - I recreated my class as a COM Class using the New Item wizard. It managed the COM GUIDs in the background, and works great. Then, I just had to register the .dll with regasm and I'm off.
chrido - I did run across an issue, and I think i know where you're coming from. I'm having to build a large XML document based on the sales order. The document is not well-formed XML, but it is a customer-prescribed standard, so I have to go with it. I wanted to use an XML Port, but couldn't find a way to do so that didn't involve a lot of file I/O, so I built the file in memory using text constants. That brought about another issue - passing a BIGTEXT variable to an external COM interface. I tried to write to an OUTSTREAM and then pass that stream to the dll, but it didn't cast correctly. Since I didn't want to get bogged down in custom COM marshalling, I just added a class-level string to my COM Class, and provided a public method called ADDTEXT which just appends to the class-level string.
If you figure out how to perform the marshalling for the IStream objects, I would like to know.
Thanks.
http://msdn2.microsoft.com/en-us/librar ... tream.aspx
Some sample code could be useful if you have done so in the past.
Thanks.
Code examples would be pointless, to be honest, because there's nothing special what I did.
I created a new Class Library and added a new item. I chose the COM Class type, which created a new class. If you use the COM Class, then the IDE manages all of the COM interop, GUIDs, delegates, etc..., for what you create in your class.
After I compiled it, I moved it to my target machine, ran "regasm Mydll.dll /tlb /codebase" (the codebase isn't really necessary, but I'm doing strong-named assemblies, so I chose to use it).
Then, all I had to do was create a new GLOBAL (important - it has to be global) automation variable in a codeunit, point it to my dll, and change the WithEvents property to TRUE. Voila - .net events in C/AL.
by the way - as for the .Net 2.0 stream example I posted earlier - it doesn't work. Apparently, even the ComClass.Istream type in the 2.0 framework shows up as IUnknown in Navision. I'm going to try some hackery with the ADO stream from the 2.7 type library to see if I can force the interop.
can you please post an example?
I've written a com class in c# wich has some events. I can see the events in navision, but if an event fires, navision hung up.
So i really like to see a working example :-)
regards
tobias
I can't post my code, because it is sensitive, but I will try to work up a simple example and post it for you.
thank you very much for your help.
I'm very anxious to see the code.
regards
tobias
Maybe this will help
This is very, very simple - just a hello world. You will have to run regasm from the .Net SDK on the .dll file. Then, import the .fob into a test Navision server.
the dispidattribute is the trick. I don't no why (havn't read the docu, yet), but it works.
@Fisherman: Your link doesn't work. I get a "Page unavailable" error.
So, thank you very much again Fisherman and aohlfsen.
regards
tobias
Good Article for understanding events and also some samples.
greetings
chris