cancel
Showing results for 
Search instead for 
Did you mean: 

Building SAP .Net Connector Server without Client connection

Former Member
0 Kudos

Hi.

I'm building a small app in VB 2013 using SAP NC0 3. It is a simple interface beetwin a digital scale with serial port and our SAP system.

With the help of differents code examples I now can make it connect with SAP and an ABAP function can retreive the data sended from my app.

The problem is that I don't want to hardcode the logon data into the app, but if I delete the Destination from the App.config file then I get an exception in sapnco.dll.

The error is: 'SAP.Middleware.Connector.RfcInvalidParameterException' in sapnco.dll.

"Destination XXX does not exist", where "XXX" is the repository destination declared in the server configuration of App.config.

Here is the line where the exception arise:

Public Const NCO_SERVER As String = "MISERVIDOR"

Public Shared Sub EjecutarServer()

            server = RfcServerManager.GetServer(NCO_SERVER, New Type() {GetType(ServerFunctionImpl)})  <<<<<< this is the line >>>>>>

            server.Start()

            frmPrincipal.txtLog.AppendText("")

            frmPrincipal.txtLog.AppendText("Servidor iniciado: " & server.Parameters.ToString())

        End Sub

Here is my App.config:

<SAP.Middleware.Connector>

    <ClientSettings>

      <DestinationConfiguration>

        <destinations>

        

Above is the line I delete, if I leave it like this my app is working, but I don't want logon data in the code.

<add NAME="XXX" USER="myuser:)" PASSWD="mypassword:)" CLIENT="100" LANG="ES" ASHOST="HERE IP" SYSNR="00" MAX_POOL_SIZE="10" IDLE_TIMEOUT="10"/>

        </destinations>

      </DestinationConfiguration>

    </ClientSettings>

    <ServerSettings>

      <ServerConfiguration>

        <servers>

          <add NAME="MISERVIDOR" GWHOST="HERE IP" GWSERV="SAPGW00" PROGRAM_ID="PROG" REPOSITORY_DESTINATION="XXX" REG_COUNT="1"/>

        </servers>

      </ServerConfiguration>

    </ServerSettings>

  </SAP.Middleware.Connector>

Any advice will be appreciate!!!

Thanks!!

Sorry about my poor english!!!

Marcos

Accepted Solutions (1)

Accepted Solutions (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Marcos,

You can serialize the repository with all needed metadata using the Save method of the RfcRepository class. In the productive version of your application you instantiate an instance of RfcCustomRepository and use Load to restore the complete metadata. In addition, you don't provide a REPOSITORY_DESTINATION for the server, but set the repository in your code to the property Repository before starting the server. Then  you will not need client credentials. Drawback of such an approach: In case you need to modify the structure somehow, you will need to re-generate the serialized repository and re-ship this instead of simply clearing the cache of the repository and do a new lookup.

Best regards,

Markus

Former Member
0 Kudos

Markus:

Thanks for your answer!!!

I understand what you are sayning, but i can't find a code example to know how to complete the task.

I also don't have a manual or reference about serialization with NCo 3.

In what format is the function metadata saved? and, how I load that metadata again before start the server?.

Pardon my insistence, I do not want to abuse your good predisposition.

Thanks in advance.

Marcos

Former Member
0 Kudos

Markus:

I managed to get a text file containing the metadata of the function.

Now I need to load that file via stramreader into my custom repository. This is my problem at this time, y don't know how to load the function metadata from the file to the custom repository.

Could you give me a hand with that?.

Many thanks!!!

Marcos

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Marcos,

it's pretty simple: the CustomRepository's Load method takes a TextReader as argument. As you stored the repository in a file, you can pass a StreamReader that takes the corresponding FileStream as source.

Best regards,

Markus

Former Member
0 Kudos

Markus:

Hi!.

I have already do that, but it seems to fail.

This is my code:

Public Class clsServer

        Public Shared Sub EjecutarServer()

            server = RfcServerManager.GetServer(NCO_SERVER, New Type() {GetType(ServerFunctionImpl)})

            fileFunc = My.Computer.FileSystem.OpenTextFileReader("C:\Users\MDORREGO\Downloads\repo.txt")

            rfcRepositorio.Load(fileFunc)

            server.Repository = rfcRepositorio

            server.Start()

            frmPrincipal.txtLog.AppendText("")

            frmPrincipal.txtLog.AppendText("Servidor iniciado: " & server.Parameters.ToString())

        End Sub

        Public Shared Sub PararServer()

            If frmPrincipal.sptSerie0.IsOpen Then frmPrincipal.sptSerie0.Close()

            server.Shutdown(True)

            End If

        End Sub

        Class ServerFunctionImpl

            <RfcServerFunction(Name:="Z_CA_OBTENER_PESO_RFC")> _

            Public Sub Z_CA_OBTENER_PESO_RFC(ByVal serverContext As RfcServerContext, ByVal rfcFunction As IRfcFunction)

                frmPrincipal.txtLog.AppendText("Llamado")

                rfcFunction.SetValue("E_PESO", varDato)

            End Sub

        End Class

    End Class

Below is the content of the file with the function metadata:

{"name":"PCD","format":"1.0","unicodeEnabled":true,"functions":[{"name":"Z_CA_OBTENER_PESO","basXmlEnabled":false,"parameters":[{"name":"E_PESO","direction":"EXPORT","optional":false,"doc":"Peso","abapType":"P","nucLength":8,"ucLength":8,"decimals":3},{"name":"I_PUESTO","direction":"IMPORT","optional":false,"doc":"Puesto","abapType":"C","nucLength":8,"ucLength":16}],"exceptions":[{"key":"ERROR_CONEXION","doc":"Peso"},{"key":"NO_EXISTE_PUESTO","doc":"Peso"},{"key":"RFC_NO_REGISTRADA","doc":"Peso"}]}]}

In SMGW under Working clients I can see my Server registered OK, but the ABAP function cannot call the function implemented in VB.

I must say that the ABAP function is working fine with an app developed in C# 2003 with an older version of a rfc connector. I don´t have the sorce of that app and I need to make a new app because the old doesn´t run in Win 7.

I don't know what is worng.

Thanks for your help!!

Marcos

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Marcos,

What is the exeption you are getting? At a first glance, both the serialized repository and the code look ok. Which NCo version are you using. Cuirrent PL is 3.0.13.

Best regards,

Markus

Former Member
0 Kudos

Markus:

Finally I found where the error was!!!

Following your guidance I was able to save the function metadata, but I saved the data of a wrong function.

Now, with the correct metadata loaded into the custom repository, my app is working fine!!

I really appreciate your help, I have no words to thanks like I want!!

Many thanks!!!

Cheers from Argentina!!

Marcos

Former Member
0 Kudos

Hi Markus Tolksdorf, Can u please look in to .

Stuck with this.

Answers (0)