SAP与RFC怎么在c#项目中进行调用

  介绍

这篇文章给大家介绍SAP与RFC怎么在c#项目中进行调用,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

结构:

 SAP与RFC怎么在c#项目中进行调用“> </p> <p>安装NuGet包:</p> <p> <img src= using  SAP.Middleware.Connector;   using  System.Data;      namespace  DFDN.SDK.ServiceInterface   {   public 才能;class  RfcDemo   {才能   ,,,public  void 加载()   ,,,{   ,,,,,RfcDestination  SapRfcDestination =, RfcDestinationManager.GetDestination (getparameter());,//连接字符串   ,,,,,RfcDestination  SapRfcDestinationForConfig =, RfcDestinationManager.GetDestination (“dad");,//连接字符串,从App.config配置   ,,,,,RfcRepository  SapRfcRepository =, SapRfcDestination.Repository;      ,,,,,DataTable  dt =, new  DataTable();,//数据源   ,,,,,dt.Columns.Add (“DATA1",, typeof (string));   ,,,,,dt.Columns.Add (“DATA2",, typeof (string));   ,,,,,dt.Columns.Add (“DATA3",, typeof (string));      ,,,,,IRfcFunction  func =, SapRfcRepository.CreateFunction (“Z_RFC_XXXX");   ,,,,,IRfcTable  tSAP =, func.GetTable (“INPUT_TABLE");      ,,,,,for  (int 小姐:=,0;,小姐:& lt;, dt.Rows.Count;,我+ +)   ,,,,,{   ,,,,,,,string  str1 =, dt.Rows[我][0].ToString ();   ,,,,,,,string  str2 =, dt.Rows[我][1].ToString ();   ,,,,,,,string  str3 =, dt.Rows[我][2].ToString ();   ,,,,,,,IRfcStructure  struSAP =, tSAP.Metadata.LineType.CreateStructure ();   ,,,,,,,struSAP.SetValue (“str1",, str1);   ,,,,,,,struSAP.SetValue (“str2",, str2);   ,,,,,,,struSAP.SetValue (“str3",, str3);   ,,,,,,,tSAP.Append (struSAP);   ,,,,,}      ,,,,,func.SetValue (“INPUT_TABLE",,的东西),,//table 参数   ,,,,,func.SetValue (“WERKS",,“A"),,,,,//单个参数,,   ,,,,,func.SetValue (“STATUS",,“B");,,//单个参数   ,,,,,func.Invoke (SapRfcDestination);,//调用      ,,,,,IRfcTable  SAPDataTable =, func.GetTable (“RETURN_TABLE");,//获取表格结果      ,,,,,DataTable  table =, ToDataTable (SAPDataTable);,//转换数据表   ,,,,,string  result =, func.GetValue (“X") .ToString();,//获取指定返回结果      ,,,}      ,,,///,& lt; summary>   ,,,///,RfcTable 转换为,数据表   ,,,///,& lt;/summary>   ,,,///,& lt; param  name=癿yrfcTable"祝辞& lt;/param>   ,,,///,& lt; returns> & lt;/returns>   ,,,public  DataTable  ToDataTable (IRfcTable  myrfcTable)   ,,,{   ,,,,,DataTable  loTable =, new  DataTable ();   ,,,,,int  liElement;   ,,,,,for  (=liElement  0;, liElement  & lt;=, myrfcTable.ElementCount 作用;1;,liElement + +)   ,,,,,{   ,,,,,,,RfcElementMetadata  metadata =, myrfcTable.GetElementMetadata (liElement);      ,,,,,,,loTable.Columns.Add (metadata.Name);   ,,,,,}      ,,,,,foreach  (IRfcStructure  Row  myrfcTable拷贝)   ,,,,,{   ,,,,,,,DataRow  ldr =, loTable.NewRow ();      ,,,,,,,for  (=liElement  0;, liElement  & lt;=, myrfcTable.ElementCount 作用;1;,liElement + +)   ,,,,,,,{   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

SAP与RFC怎么在c#项目中进行调用