NAS and VB.NET: Reading reply in .NET

dpardomdpardom Member Posts: 74
Hi,
I have a working codeunit in navision, wich receives a xml, parse it, and send result back as reply.

Until here all right, but, when trying to read the reply from .NET it throws an "unexpected exception".

For msmq I'm using the navision dll's

The .NET code is:
            Dim ComCom As New NSCOMCOM2Lib.CommunicationComponent
            Dim msmq As New MSMQBUSADAPTERLib.MSMQBusAdapter()
            Dim m As MessageQueue
            Dim comOut As NSCOMCOM2Lib.IOutMessage



            Try
                msmq.OpenWriteQueue(mstrPath, 0, 0)
                msmq.OpenReceiveQueue(mstrPathReceive, 0, 0)

                ComCom.AddBusAdapter(msmq, 0)
            Catch ex As Exception

            End Try


            Dim enconding As Text.UnicodeEncoding

            'information must be UTF8
            Dim [Unicode] As Encoding = Encoding.GetEncoding("UTF-8")
            Dim asciiBytes As Byte() = [Unicode].GetBytes(oPeticion.GenerarXML())

            Try
                Dim i As Integer
                For i = 0 To asciiBytes.Length - 1
                    ci.RemoteWrite(asciiBytes(i), 1, 8)
                Next
             Catch ex As Exception
                .......
            End Try

            Dim comIn As NSCOMCOM2Lib.IInMessage

            Dim co As NSCOMCOM2Lib.IStream
            Dim respuesta As Byte()

            'Send XML to the queue and wait reply...

            Try
                comIn = comOut.SendWaitForReply(10000)
            Catch ex As TimeoutException
                Return False
            Catch ex As Exception
                Return False
            End Try


At the end, comIn has as value something like "unexpected exception".

Help please. [-o<

Comments

  • jlandeenjlandeen Member Posts: 524
    Have you tried using any of the standard MSMQ components that come with .Net. (I'm assuming you're using VB.Net and not an older version of VB) Instead of using Navision's DLL's have you should consider using with the System.Messaging objects that are available in the base .Net classes.

    There is lots of documentation on the internet to explain how these work. These classes also provide a lot more functionality then the Navision DLLs. I think you will find it a lot easier to use & debug any code that is based on this (as the VS debugging is a billion times better then Navisions).

    I think there is also a number of whitepapers on making VB talk to .net to be found on Mibuso and in partnersource.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • jlandeenjlandeen Member Posts: 524
    Oops...that last line was supposed to be: I think there is also a number of whitepapers on making .Net talk to Navision to be found on Mibuso and in partnersource.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • dpardomdpardom Member Posts: 74
    Thanks for reply.

    I were trying to use the .NET classes, but didn't find anything like 'SendWaitForReply'... maybe I just need to read more about queue handling.

    Thanks again
  • jlandeenjlandeen Member Posts: 524
    It's been a couple months since I've done anything like this...and I don't have the source code readily available...but basically you need to setup your Message Queue object so that it will receive a response. This is done through setting of properties on either the Message object or the Queue object (or both). You should hunt around MSDN for working with Message Queues. There should be a timeout that you set to wait for the response message...and then if you don't get one an error will occur.

    If you are using the MSMQ objects that come with Navision it is very important that you you use the collation ID in your response message (I think there's UseCollationID flag somewhere) and that your message has the correct label ('Navision MSMQ-BA'). The label tells the Navision comcom DLL to pay attention to the message, and the collation ID is used by MSMQ and .Net to match the outbound message with it's corresponding response message.

    Check out MSDN, play around with some sample code and googgle should help you get everything working together.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.