How can I connect to SAP from C# through the SAP NetWeaver RFC Library (sapnwrfc.dll)?
-
23-09-2019 - |
문제
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.
다른 팁
단순한 답변 : 아니오.
원시 출력은 페이지의 구성 요소 출력 만 표시합니다.
이 대신 tmpl=component
를 사용해보십시오.