前端调用WCF接口的方法

    xiaoxiao2022-06-27  164

    1:引用WCf。需要用到:Service References

    2:引用成功之后,需要创建连接wcf的通道。新建一个类:BaseData,声明一个成员变量  basicData

    3:在构造函数里面创建通道。

    4:GetCardDiscount方法就是具体的调用wcf内部接口的方法。

     

    namespace GTOW.DAL.WCF {     public class BaseData     {         private BasicDataServiceReference.IBasicDataOperate basicData;         public BaseData()         {             CreateChannel();         }    

            /// <summary>         /// 创建通道初始连接         /// </summary>         /// <returns></returns>         private IBasicDataOperate CreateChannel()         {             try             {                 //string basicDataAddress = ConfigurationManager.AppSettings["BasicDataAddress"];

                    string basicDataAddress = GTOW.ConfigManager.ConfigCenterValue.Instance.GetByString("BasicDataAddress");

     

                    BasicHttpBinding basicTcp = new BasicHttpBinding();                 basicTcp.MaxReceivedMessageSize = int.MaxValue;                 basicTcp.Security.Mode = BasicHttpSecurityMode.None;                 string BasicDataHostAddress = basicDataAddress;// "http://222.66.142.19:9301/bdo/";                 ChannelFactory<IBasicDataOperate> channel = new ChannelFactory<IBasicDataOperate>(basicTcp, BasicDataHostAddress);                 basicData = channel.CreateChannel();                 return basicData;             }             catch (Exception ex)             {                 return null;             }         }

          /// <summary>         ///  会员卡折扣        /// </summary>        /// <param name="intCardKind">卡类型</param>        /// <param name="strHotelCode">酒店编号</param>        /// <param name="dateTime">日期</param>        /// <returns></returns>         public decimal GetCardDiscount(int intCardKind, string strHotelCode,string dateTime)         {             M625OperateInfo m625 = new M625OperateInfo { operatorID = "998", ResvSource = "998" };             return basicData.GetCardDiscount_V2(m625, intCardKind, strHotelCode, dateTime);         }

     

    }


    最新回复(0)