internet business consulting: martin soltis


Programming Tips & Tricks
Fishbowl Inventory SDK Integration with VB.Net
Seems like there are a lot of questions floating around about integrating Fishbowl using their SDK and VB.Net. I've cleaned up my code & have chopped quite a bit out, but am pretty sure everything is still intact. This should at least get you rolling.
  • Add the miscUtil.dll to your /Bin directory
  • fish.getKey() - This just reutrns the xml for the ticket request. You will have to update it with your app name, user name and password.
  • fish.data.encrypt(str) - Returns the forward-only encryption for the password
  • fish.data.socketSend(fishbowlXML) - Sends the xml to Fishbowl. You'll have to update it with the IP address and port of the Fishbowl server.
    I have it returning "PASS" or "FAIL" after processing the response XML (not shown).

Good luck!


 

Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports FirebirdSql.Data
Imports FirebirdSql.Data.FirebirdClient
Imports System.IO
Imports System.Net.Sockets
Imports System.Text
Imports MiscUtil.Conversion
Imports MiscUtil.IO

Public Class fish

    Public Shared Function getKey()
        'JUST BUILDS THE TICKET/KEY REQUEST 
        Dim xml As String = "<FbiXml><Ticket/><FbiMsgsRq><LoginRq><IAID>00010</IAID><IAName>[your app name]</IAName>_
        <IADescription>Sends XML to Fishbowl</IADescription><UserName>[username]</UserName><UserPassword>"_
         & data.encrypt("[password]") & "</UserPassword></LoginRq></FbiMsgsRq></FbiXml>"

        getKey = xml


    End Function
    Public Class data
        Public Shared Function encrypt(ByVal str As String)

            Dim encoder As New UTF8Encoding
            Dim input As Byte() = encoder.GetBytes(str)
            Dim output As Byte() = System.Security.Cryptography.MD5CryptoServiceProvider.Create().ComputeHash(input)

            Return Convert.ToBase64String(output)

        End Function

        Public Shared Function socketSend(ByVal fishbowlXML as string)
            socketSend = "FAIL"
            Dim enc As New System.Text.ASCIIEncoding, doc As New System.Xml.XmlDocument
            Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            Dim ip As System.Net.IPAddress = System.Net.IPAddress.Parse("[ip address of FB server")
            Dim ep As New System.Net.IPEndPoint(ip, [port_number_of_fishbowl_as_int])
            sock.SendTimeout = 800

            Try
                sock.Connect(ep)
                Dim ns = New NetworkStream(sock)
                Dim outputstream = New EndianBinaryWriter(New BigEndianBitConverter(), ns)
                Dim inputstream = New EndianBinaryReader(New BigEndianBitConverter(), ns)
                'SEND KEY REQUEST TO FISHBOWL
                'THIS WILL EITHER ERROR & FAIL OR RETURN KEY XML
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(fish.getKey())

                outputstream.write(sendBytes.Length)
                outputstream.write(sendBytes)
                outputstream.flush()

                sendBytes = Nothing

                Dim i As Integer = inputstream.readint32()
                Dim respBytes As Byte()
                ReDim respBytes(i)
                inputstream.read(respBytes, 0, i)
                doc.LoadXml(Encoding.UTF8.GetString(respBytes, 0, i))
                respBytes = Nothing
                'READ STATUS CODE FROM XML RETURNED FROM FB
                Dim statuscode As String = doc.DocumentElement.LastChild.Attributes("statusCode").Value


                If statuscode = "1000" Then
                    '1000 = SUCCESS
                    'we have the app key - write the order to Fishbowl Inventory

                    Dim key As String = doc.GetElementsByTagName("Key").Item(0).FirstChild.InnerText
                    Dim oBytes As [Byte]() = Encoding.ASCII.GetBytes("<FbiXml><Ticket><Key>" & key & "</Key></Ticket><FbiMsgsRq>"_
                     & fishbowlXML & "</FbiMsgsRq></FbiXml>")
                     
                    outputstream.write(oBytes.Length)
                    outputstream.write(oBytes)
                    outputstream.flush()
                    oBytes = Nothing
                    i = inputstream.readint32()
                    Dim rBytes As Byte()
                    ReDim rBytes(i)
                    inputstream.read(rBytes, 0, i)

                    doc.LoadXml(Encoding.UTF8.GetString(rBytes, 0, i))
                    'this XML HAS THE RESPONSE FROM FISHBOWL
                    'PROCESS IT AS YOU WISH
                    socketSend = "PASS"

                Else
                    socketSend = "FAIL"

                End If


            Catch ex As Exception
                socketSend = "FAIL"

            End Try

            If sock.Connected Then
                sock.Close()
            End If

        End Function

    End Class

End Class