WCF 服务调用RFC 出现异常

我在VS2010的WCF项目用connecter 3.0 调用 RFC  运行到
       IDestinationConfiguration ID = new SAPConfig();
      RfcDestinationManager.RegisterDestinationConfiguration(ID);
出现异常如下:
“SAP.Middleware.Connector.RfcDestinationManager”的类型初始值设定项引发异常。
其innerexception 是{"当不在独立 exe 内部运行时,必须指定 exePath。"}

在 http://bbs.csdn.net/topics/390317439  找到方法解决

你的web.config 有没有
<system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

 

但是这个要在服务里面增加 属性 有没有权限整个项目加

[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]
后来发现

//SAP.Middleware.Connector 里面通过HttpContext.Current来判断这是一个web还是winform程序
//但是在WCF里面HttpContext.Current为null 所以在wcf里面会判断出错 导致取配置文件出错
//人工新建一个HttpContext.Current 创建好连接后在手工置为null。很傻很天真...
HttpContext.Current = new HttpContext(new HttpRequest("", "http://127.0.0.1/", ""),
new HttpResponse(new StringWriter()));

//创建连接
RfcDestination RfcDes = rfcConfig.RfcConfiguration(sapCon);
HttpContext.Current = null;

 IRfcFunction func = RfcDes.Repository.CreateFunction("Z_TR_I_101_N"); 

然后就可以了...



posted @ 2013-12-19 10:40  鱼香茄子  阅读(1382)  评论(5编辑  收藏  举报