K2 BPM项目 基于COM组件调用SAP RFC 问题
问题前景:
环境:Win 2008 R2 64bit
最近项目中有支流程需求中需要在会计入账环节回写SAP的会计凭证。
SAP组给我们提供.NET基于COM组件调用SAP RFC的函数及参数,花费大量时间查阅资料终于知道怎么调用该函数:
SAPHelper.cs
1 private string CompanyCode { get; set; } 2 private string ProofDate { get; set; } 3 private string PostDate { get; set; } 4 private string OutSub { get; set; } 5 private string InSub { get; set; } 6 private string Amount { get; set; } 7 private string Currency { get; set; } 8 private string Text { get; set; } 9 private string UserAccount { get; set; } 10 private bool Flag { get; set; } 11 12 public bool MoneyTransfer(string CompanyCode, string ProofDate, string PostDate, string OutSub, string InSub, string Amount, string Currency, string Text, string UserAccount) 13 { 14 this.CompanyCode = CompanyCode; 15 this.ProofDate = ProofDate; 16 this.PostDate = PostDate; 17 this.OutSub = OutSub; 18 this.InSub = InSub; 19 this.Amount = Amount; 20 this.Currency = Currency; 21 this.Text = Text; 22 this.UserAccount = UserAccount; 23 Thread s = new Thread(new ThreadStart(Transfer)); 24 s.SetApartmentState(System.Threading.ApartmentState.STA);//Set the run mode 'STA' 25 s.Start();//Start the thread 26 s.Join(); //Wait until thread run OK. 27 return Flag; 28 } 29 /// <summary> 30 /// 公司内部调拨凭证生成接口 31 /// </summary> 32 /// <param name="I_BUKRS">公司代码</param> 33 /// <param name="I_BLDAT">凭证日期</param> 34 /// <param name="I_BUDAT">过账日期</param> 35 /// <param name="I_OSAKNR">转出科目</param> 36 /// <param name="I_ISAKNR">转入科目</param> 37 /// <param name="I_WRBTR">金额</param> 38 /// <param name="I_WAERS">货币</param> 39 /// <param name="I_SGTXT">项目文本</param> 40 /// <param name="I_USERNAME">操作用户</param> 41 private void Transfer() 42 { 43 Connection conn = GetConnection(); 44 try 45 { 46 //登陆 47 if (conn.Logon(null, true)) 48 { 49 SAPFunctionsClass functions = new SAPFunctionsClass(); 50 functions.Connection = conn; 51 //传入Function Name 52 Function fucntion = (Function)functions.Add("ZFI_FM005"); 53 #region 传入值参数 54 Parameter pCompanyCode = (Parameter)fucntion.get_Exports("I_BUKRS"); 55 pCompanyCode.Value = CompanyCode; 56 Parameter pProofDate = (Parameter)fucntion.get_Exports("I_BLDAT"); 57 pProofDate.Value = ProofDate; 58 Parameter pPostDate = (Parameter)fucntion.get_Exports("I_BUDAT"); 59 pPostDate.Value = PostDate; 60 Parameter pOutSub = (Parameter)fucntion.get_Exports("I_OSAKNR"); 61 pOutSub.Value = OutSub; 62 Parameter pInSub = (Parameter)fucntion.get_Exports("I_ISAKNR"); 63 pInSub.Value = InSub; 64 Parameter pAmount = (Parameter)fucntion.get_Exports("I_WRBTR"); 65 pAmount.Value = Amount; 66 Parameter pCurrency = (Parameter)fucntion.get_Exports("I_WAERS"); 67 pCurrency.Value = Currency; 68 Parameter pText = (Parameter)fucntion.get_Exports("I_SGTXT"); 69 pText.Value = Text; 70 Parameter pUserAccount = (Parameter)fucntion.get_Exports("I_USERNAME"); 71 pUserAccount.Value = UserAccount; 72 #endregion 73 //传出参数 74 Parameter OutPut = (Parameter)fucntion.get_Imports("I_RETURN"); 75 //调用函数 76 if (fucntion.Call()) 77 { 78 #region 79 string s = OutPut.Value.ToString(); 80 //to do 81 if (s.Contains("错误")) 82 { 83 this.Flag = false; 84 } 85 else 86 { 87 this.Flag = true; 88 } 89 #endregion 90 } 91 } 92 //退出登陆 93 conn.Logoff(); 94 } 95 catch (COMException ex) 96 { 97 conn.Logoff(); 98 Flag= false; 99 } 100 } 101 102 private Connection GetConnection() 103 { 104 SAPLogonControlClass connctl = new SAPLogonControlClass(); 105 106 connctl.Client = ConfigurationManager.AppSettings["SAPClient"]; 107 connctl.Language = "ZH"; 108 connctl.ApplicationServer = ConfigurationManager.AppSettings["ApplicationServer"]; 109 connctl.SystemNumber = 00; 110 connctl.User = ConfigurationManager.AppSettings["SAPUser"]; 111 connctl.Password = ConfigurationManager.AppSettings["SAPPassword"]; 112 113 return (Connection)connctl.NewConnection(); 114 }
调用:
1 SAPService service = new SAPService(); 2 this.ContinueProcessFlag = service.MoneyTransfer(txtPayCompanySAPCode.Text.Trim(), txtTransferDate.Text.Trim(), txtTransferDate.Text.Trim(), txtPaySAPAccountCode.Text, txtInComeSAPAccountCode.Text, txtPayAmountLow.Text, "CNY", txtTransferReason.Text, WebContext.Current.CurrentEmployee.UserAccount);
编译完后调试,OK。
本地调试OK。
然而发布到IIS上后问题出现了:
发布后调用调试IIS(怎么调试略),发现在if (conn.Logon(null, true))停留,无法登录。
经过研究与查阅大量资料后,基本确定问题是在与IIS在调用组件的权限问题上。根据http://wenku.it168.com/d_001035865.shtml 配置DCOM权限将“启动与激活”和“访问权限”改为自定义并加上EveryOne权限,将标识改为“交互式用户”,IIS应用程序池使用的是隶属于管理员组的域帐号,托管管道模式使用的是集成模式:
然而问题依旧,尝试过将应用程序池域帐号,IUSR组,IIS_WPG组加到“访问权限”和“启动和激活权限”,未果。
期待各位大虾门指点思路。
posted on 2013-08-13 15:41 Cassie,zh 阅读(1320) 评论(4) 编辑 收藏 举报