How to build a RFC Server with NCo 3.0 Part 2

So it is done, Part 2 finally is written and an example is uploaded to github. It took me about 8 months to release Part 2 of these series. Part 1 was released in March 2016 and now I had time to write an example for Part 2 and upload it to github. Part 1 discover the basics about a RFC Server with the SAP NCo Connector, part 2 now explain how to build a RFC Server more flexible.

First you have to create a new Microsoft Visual Studio project. In my case it was a Windows Form Application. I add some labels and textboxes so it look like this:

SAP NCo RFC Server Sample Part 2
SAP NCo RFC Server Sample Part 2

I also add some fields in the application settings:

Visual Studio Project Settings
Visual Studio Project Settings

After the fields are done, we can add our code for the save button.

With My.Settings

.RfcProgramId = txtProgramID.Text .

.RfcGatewayHost = txtGatewayHost.Text

.RfcGatewayService = txtGatewayService.Text

.RfcIdleTimeout = txtIdleTimeout.Text

.RfcMessageServer = txtMessageServerHost.Text

.RfcMessageServerService = txtMessageServerService.Text

.RfcMessageServerSystemID = txtMessageServerSystemId.Text

.RfcLanguage = txtLanguage.Text

.RfcPassword = txtPassword.Text

.RfcUser = txtUser.Text

.RfcRegistrationCount = txtRegistrationCount.Text

My.Settings.Save()

End With

So now we are able to save our settings directly into the application settings. To switch between normal mode (able to save the settings) and a console mode I add a new module which checks if there are any arguments. In this case I check if the argument -R (remote) is available.

Public Sub Main()

Dim args() As String = Environment.GetCommandLineArgs()

If args.Length > 0 And String.Equals(args(1).ToUpper, "-R") Then

Dim remoteServer As RfcServer

Dim parameters As New RfcConfigParameters()

parameters(RfcConfigParameters.Name) = "NCO_SERVER"

Dim repository As String

With My.Settings

If String.IsNullOrEmpty(.RfcProgramId) OrElse String.IsNullOrEmpty(.RfcGatewayHost) OrElse String.IsNullOrEmpty(.RfcGatewayService) OrElse String.IsNullOrEmpty(.RfcIdleTimeout) OrElse String.IsNullOrEmpty(.RfcLanguage) OrElse String.IsNullOrEmpty(.RfcPassword) OrElse String.IsNullOrEmpty(.RfcUser) OrElse String.IsNullOrEmpty(.RfcRegistrationCount) Then

MessageBox.Show("Please fill all necessary fields!", "Missing fields", MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit Sub

End If

parameters(RfcConfigParameters.ProgramID) = .RfcProgramId

parameters(RfcConfigParameters.GatewayHost) = .RfcGatewayHost

parameters(RfcConfigParameters.GatewayService) = .RfcGatewayService

parameters(RfcConfigParameters.ConnectionIdleTimeout) = .RfcIdleTimeout

parameters(RfcConfigParameters.MessageServerHost) = .RfcMessageServer

parameters(RfcConfigParameters.MessageServerService) = .RfcMessageServerService()

parameters(RfcConfigParameters.SystemID) = .RfcMessageServerSystemID

parameters(RfcConfigParameters.User) = .RfcUser

parameters(RfcConfigParameters.Password) = .RfcPassword

parameters(RfcConfigParameters.Language) = .RfcLanguage

parameters(RfcConfigParameters.RegistrationCount) = .RfcRegistrationCount

End With

remoteServer = RfcServerManager.GetServer(parameters, New Type() {GetType(ServerFunction)})

repository = CStr(My.Resources.ResourceManager.GetObject("repo"))

Dim fileFunc As New StringReader(repository)

Dim rfcRepository As New RfcCustomRepository

rfcRepository.Load(fileFunc)

remoteServer.Repository = rfcRepository

remoteServer.Start()

Thread.Sleep(400000)

Else

Dim server As New NCoServer

server.ShowDialog()

End If

End Sub

You can check if the argument works when you add in the project properties under debug -R

Visual Studio Project Properties Command line arguments
Visual Studio Project Properties Command line arguments

So if you run now Visual Studio in debug mode, the command line argument is executed. And code after this if will be executed.

If args.Length > 0 And String.Equals(args(1).ToUpper, "-R") Then

So as you can see the RFC Server is build from the previous defined settings and it is more flexible than Part 1. And after we started the function module as in Part 1 described, our RFC Server now response.

SAP NCo RFC Server Response after call from NetWeaver BW
SAP NCo RFC Server Response after call from NetWeaver BW

So that's it. I hope you like the quick example and if there are any questions feel free to ask.

author.


I am Tobias, I write this blog since 2014, you can find me on twitter and youtube. If you want you can leave me a paypal coffee donation. You can also contact me directly if you want.

SAP Analysis for Office - The Comprehensive Guide
The book SAP Analysis for Office - The Comprehensive Guide by Tobias Meyer is a pdf book about SAP Analysis for Office. It is based on Analysis for Office 2.8 and contains 346 Pages.
45,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.7 and contains 299 Pages.
37,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.6 and contains 272 Pages.
27,00 €

Write a comment

Comments: 0