K2 BPM项目 基于COM组件调用SAP RFC 问题

K2 BPM项目 基于COM组件调用SAP RFC 问题

问题前景:

  环境:Win 2008 R2 64bit

  最近项目中有支流程需求中需要在会计入账环节回写SAP的会计凭证

  SAP组给我们提供.NET基于COM组件调用SAP RFC的函数及参数,花费大量时间查阅资料终于知道怎么调用该函数:

 

SAPHelper.cs

复制代码
  View Code

private string CompanyCode { get; set; }
private string ProofDate { get; set; }
private string PostDate { get; set; }
private string OutSub { get; set; }
private string InSub { get; set; }
private string Amount { get; set; }
private string Currency { get; set; }
private string Text { get; set; }
private string UserAccount { get; set; }
private bool Flag { get; set; }

public bool MoneyTransfer(string CompanyCode, string ProofDate, string PostDate, string OutSub, string InSub, string Amount, string Currency, string Text, string UserAccount)
{
this.CompanyCode = CompanyCode;
this.ProofDate = ProofDate;
this.PostDate = PostDate;
this.OutSub = OutSub;
this.InSub = InSub;
this.Amount = Amount;
this.Currency = Currency;
this.Text = Text;
this.UserAccount = UserAccount;
Thread s = new Thread(new ThreadStart(Transfer));
s.SetApartmentState(System.Threading.ApartmentState.STA);//Set the run mode 'STA'
s.Start();//Start the thread
s.Join(); //Wait until thread run OK.
return Flag;
}
/// <summary>
/// 公司内部调拨凭证生成接口
/// </summary>
/// <param name="I_BUKRS">公司代码</param>
/// <param name="I_BLDAT">凭证日期</param>
/// <param name="I_BUDAT">过账日期</param>
/// <param name="I_OSAKNR">转出科目</param>
/// <param name="I_ISAKNR">转入科目</param>
/// <param name="I_WRBTR">金额</param>
/// <param name="I_WAERS">货币</param>
/// <param name="I_SGTXT">项目文本</param>
/// <param name="I_USERNAME">操作用户</param>
private void Transfer()
{
Connection conn = GetConnection();
try
{
//登陆
if (conn.Logon(null, true))
{
SAPFunctionsClass functions = new SAPFunctionsClass();
functions.Connection = conn;
//传入Function Name
Function fucntion = (Function)functions.Add("ZFI_FM005");
#region 传入值参数
Parameter pCompanyCode = (Parameter)fucntion.get_Exports("I_BUKRS");
pCompanyCode.Value = CompanyCode;
Parameter pProofDate = (Parameter)fucntion.get_Exports("I_BLDAT");
pProofDate.Value = ProofDate;
Parameter pPostDate = (Parameter)fucntion.get_Exports("I_BUDAT");
pPostDate.Value = PostDate;
Parameter pOutSub = (Parameter)fucntion.get_Exports("I_OSAKNR");
pOutSub.Value = OutSub;
Parameter pInSub = (Parameter)fucntion.get_Exports("I_ISAKNR");
pInSub.Value = InSub;
Parameter pAmount = (Parameter)fucntion.get_Exports("I_WRBTR");
pAmount.Value = Amount;
Parameter pCurrency = (Parameter)fucntion.get_Exports("I_WAERS");
pCurrency.Value = Currency;
Parameter pText = (Parameter)fucntion.get_Exports("I_SGTXT");
pText.Value = Text;
Parameter pUserAccount = (Parameter)fucntion.get_Exports("I_USERNAME");
pUserAccount.Value = UserAccount;
#endregion
//传出参数
Parameter OutPut = (Parameter)fucntion.get_Imports("I_RETURN");
//调用函数
if (fucntion.Call())
{
#region
string s = OutPut.Value.ToString();
//to do
if (s.Contains("错误"))
{
this.Flag = false;
}
else
{
this.Flag = true;
}
#endregion
}
}
//退出登陆
conn.Logoff();
}
catch (COMException ex)
{
conn.Logoff();
Flag= false;
}
}

private Connection GetConnection()
{
SAPLogonControlClass connctl = new SAPLogonControlClass();

connctl.Client = ConfigurationManager.AppSettings["SAPClient"];
connctl.Language = "ZH";
connctl.ApplicationServer = ConfigurationManager.AppSettings["ApplicationServer"];
connctl.SystemNumber = 00;
connctl.User = ConfigurationManager.AppSettings["SAPUser"];
connctl.Password = ConfigurationManager.AppSettings["SAPPassword"];

return (Connection)connctl.NewConnection();
}

复制代码

调用:

复制代码
  View Code

SAPService service = new SAPService();
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应用程序池使用的是隶属于管理员组的域帐号,托管管道模式使用的是集成模式:

K2 BPM项目 基于COM组件调用SAP RFC 问题K2 BPM项目 基于COM组件调用SAP RFC 问题

 

然而问题依旧,尝试过将应用程序池域帐号,IUSR组,IIS_WPG组加到“访问权限”和“启动和激活权限”,未果。

期待各位大虾门指点思路。

 

 
 
分类:  ASP.NET
标签:  ASP.NETSAPBPMK2

你可能感兴趣的:(SAP,asp.net,BPM,K2)