开发者

How can I connect to SAP using sapnwrfc library?

Our software is written in C# and needs to connect to SAP. As some of our customers use older versions of SAP, and others don't have SAP PI, we can't connect through webservices.

I tried to connect to SAP through the SAP NetWeaver Remote Function Call Library (sapnwrfc.dll) as follows:

  • Add sapnwrfc.dll and the other dlls from NWRFC_6-20004550.SAR (being icudt34.dll, icuin34.dll, icuuc34.dll, libicudecnumber.dll, and libsapucum.dll) to C:\WINDOWS\system32, to be sure that they can be found.
  • In my C# code add the following in the class definition:

        [DllImport("sapnwrfc.dll", CharSet = CharSet.Auto)]

        public static extern void RfcInit();

    and the following in the method that should do the work:

        RfcInit();

Running this code gives a DllNotFoundException:

Unable to load DLL 'sapnwrfc.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)

Running the standard connect-to-C++-from-C# example

    [DllImport("user32.dll", CharSet = CharSet.Unicode开发者_开发知识库)]

    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

    MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);

works fine.

Any suggestions how to make this work fine (so that we don't need to workaround this problem by writing a Java proxy using JCo)?


Did you check with the Dependency Viewer if you are missing some DLL? I did once write a managed wrapper for the rfc library (at least part of it) and I remember having a problem with some of the rfc libraries I downloaded. One version simply did not work and I did not figure out what was wrong. Another version (older) worked just fine.

I did however have problems with the unicode library (some memory access problem that appeared randomly) so I had to switch to the non-unicode version...

If I had to do something like this again, I would very seriously consider to buy a connector: http://www.theobald-software.com/en/products/erpconnect.htm

I cannot say if it is any good, but they seem to be around for a while now.


Why don't you simply use SAP's ".NET Connector" (NCo3)? See SAP note 856863 for a link to the download page and documentation.


Please try to copy icudt34.dll, icuin34.dll, icuuc34.dll, libicudecnumber.dll, and libsapucum.dll to the directory of your project's bin. I had try it and it works well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜