zoukankan      html  css  js  c++  java
  • 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"); 

    然后就可以了...



  • 相关阅读:
    C#中的委托和事件(续)【来自张子扬】
    C# 中的委托和事件[转自张子扬]
    .NET多线程编程入门
    python——configparser模块
    logger模块
    python——time模块
    os模块
    python——re模块
    selenium环境搭建
    iOS中的三大定时器
  • 原文地址:https://www.cnblogs.com/szfxsl/p/3481671.html
Copyright © 2011-2022 走看看