设为首页 收藏本站
查看: 1267|回复: 0

[经验分享] K2 BPM项目 基于COM组件调用SAP RFC 问题

[复制链接]

尚未签到

发表于 2015-9-17 13:12:36 | 显示全部楼层 |阅读模式
  问题前景:
  环境:Win 2008 R2 64bit
  最近项目中有支流程需求中需要在会计入账环节回写SAP的会计凭证。
  SAP组给我们提供.NET基于COM组件调用SAP RFC的函数及参数,花费大量时间查阅资料终于知道怎么调用该函数:
  
  SAPHelper.cs


DSC0000.gif DSC0001.gif


  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         }
View Code   调用:





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);
View Code   
  编译完后调试,OK。
  本地调试OK。
  然而发布到IIS上后问题出现了:
  发布后调用调试IIS(怎么调试略),发现在if (conn.Logon(null, true))停留,无法登录。
  经过研究与查阅大量资料后,基本确定问题是在与IIS在调用组件的权限问题上。根据http://wenku.it168.com/d_001035865.shtml 配置DCOM权限将“启动与激活”和“访问权限”改为自定义并加上EveryOne权限,将标识改为“交互式用户”,IIS应用程序池使用的是隶属于管理员组的域帐号,托管管道模式使用的是集成模式:
DSC0002.jpg DSC0003.jpg
  
  然而问题依旧,尝试过将应用程序池域帐号,IUSR组,IIS_WPG组加到“访问权限”和“启动和激活权限”,未果。
  期待各位大虾门指点思路。
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-114986-1-1.html 上篇帖子: SAP交易命令含义对照,加深记忆 下篇帖子: 尘埃落定,回顾我的漫漫求职路(SAP篇)——上海之行
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表