Sharing, walaupun di internet sudah banyak beredar cara-caranya.
Ada pekerjaan web application yang membutuhkan akses ke AS/400 dan menjalankan program yang telah ada pada AS/400.
Untuk dapat menjalankan program dalam AS/400 dibutuhkan cwbx.dll yang ada pada instalasi IBM Client-Server. Kebetulan saya menggunakan versi 5 release 3. Cukup mudah, add saja cwbx.dll tersebut ke dalam project web pada VS 2005 anda. VS akan mengubah DLL tersebut menjadi Interop component.
Shared Function Configure(ByRef AS400Library As String, ByRef ProgramName As String, ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program) As Boolean
TheSystem.Define(ConfigurationManager.AppSettings.Item(“AS400Server”))
TheSystem.UserID = ConfigurationManager.AppSettings.Item(
“AS400UserID”)TheSystem.Password = ConfigurationManager.AppSettings.Item(
“AS400Password”)TheProgram.system = TheSystem
With
TheProgram
.LibraryName = AS400Library
.ProgramName = ProgramName
End With
Return True
End Function
Script diatas adalah script untuk melakukan konfigurasi terhadap koneksi ke AS/400, dimana kebetulan saya menggunakan APPSETTING yang ditulis di web.config. Selanjutnya adalah membuat suatu function yang berfungsi memanggil program di AS/400.
Shared Function CallProgram(ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program, ByRef parameters As cwbx.ProgramParameters) As Boolean
Try
If (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0) ThenTheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)
TheSystem.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd)
If (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0) Then
Return False
End If
End IfTheProgram.Call(parameters)
Return True
Catch ex As Exception
Throw ex
Finally
If
Not (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0)
Then
TheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)
End
If
End Try
End Function
Selesai, anda tinggal mengkombinasikan 2 function di atas dengan menyebutkan library dan nama program beserta parameter-parameter dari program tersebut (bila ada).
