當前位置: 首頁>>代碼示例>>C#>>正文


C# ChannelFactory.GetType方法代碼示例

本文整理匯總了C#中System.ServiceModel.ChannelFactory.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.GetType方法的具體用法?C# ChannelFactory.GetType怎麽用?C# ChannelFactory.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ServiceModel.ChannelFactory的用法示例。


在下文中一共展示了ChannelFactory.GetType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CallEventWCFService

        /// <summary>
        /// 調用WCF
        /// </summary>
        /// <param name="ContractType"></param>
        /// <param name="BindingName"></param>
        /// <param name="Endaddress"></param>
        /// <param name="FuncName"></param>
        /// <param name="strValue"></param>
        /// <returns></returns>
        public static object CallEventWCFService(string ContractType, string BindingName, string Endaddress, string FuncName, string strValue)
        {

            EndpointAddress endPoint = new EndpointAddress(Endaddress);//地址
            string XmlTemplete = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "\r\n" +
                                    "<System>" + "\r\n" +
                                    "{0}" +
                                    "</System>";
            if (ContractType.ToUpper() == "ENGINE")
            {
                IApplicationService contract = new ChannelFactory<IApplicationService>(WCfBindingName(BindingName), endPoint).CreateChannel();
                Type type = contract.GetType();
                MethodInfo methodInfo = type.GetMethod(FuncName);
                strValue = string.Format(XmlTemplete, strValue);
                string[] param = new string[1];
                param[0] = strValue;
                return methodInfo.Invoke(contract, param);
            }
            else
            {             
                using (ChannelFactory<IEventTriggerProcess> channel = new ChannelFactory<IEventTriggerProcess>(WCfBindingName(BindingName), endPoint))
                {
                    IEventTriggerProcess instance = channel.CreateChannel();
                    using (instance as IDisposable)
                    {
                        try
                        {
                            Type type = typeof(IEventTriggerProcess);
                            MethodInfo mi = type.GetMethod(FuncName);
                            strValue = string.Format(XmlTemplete, strValue);
                            string[] param = new string[1];
                            param[0] = strValue;
                            //Log.WriteLog("調用服務驗證Endaddress:" + Endaddress + "strValue:" + strValue);
                            return mi.Invoke(instance, param);
                        }
                        catch (TimeoutException tm)
                        {
                            (instance as ICommunicationObject).Abort();
                            //Log.WriteLog("調用服務驗證TimeoutException" + tm.StackTrace);
                            throw;
                        }
                        catch (CommunicationException com)
                        {
                            (instance as ICommunicationObject).Abort();
                            //Log.WriteLog("調用服務驗證CommunicationException" + com.StackTrace);
                            throw;
                        }
                        catch (Exception vErr)
                        {
                            //Log.WriteLog("調用服務驗證Exception" + vErr.StackTrace);
                            (instance as ICommunicationObject).Abort();
                            throw;
                        }
                    }
                }
            }
        }
開發者ID:JuRogn,項目名稱:OA,代碼行數:66,代碼來源:Utility.cs

示例2: CallWCFService

 /// <summary>
 /// 流程調用的方法
 /// </summary>
 /// <param name="BindingName">bindingName</param>
 /// <param name="Endaddress">endaddress</param>
 /// <param name="FuncName">funcName</param>
 /// <param name="strValue">strValue</param>
 /// <returns>object</returns>
 public static object CallWCFService(string bindingName, string endaddress, string funcName, string strValue,ref string erroMesssage)
 {
     //綁定不同的協議未測試,討論一下最好的方法,或者或者做一個CASE,讓用戶填好
     try
     {
         EndpointAddress endPoint = new EndpointAddress(endaddress);//地址
         IApplicationService contract = new ChannelFactory<IApplicationService>(WCfBindingName(bindingName), endPoint).CreateChannel();
         Type type = contract.GetType();
         MethodInfo methodInfo = type.GetMethod(funcName);
         string[] param = new string[1];
         param[0] = strValue;
         return methodInfo.Invoke(contract, param);
     }
     catch (Exception e)
     {
         string cMessage = "\r\n 動態 調用第三方服務出錯 命名空間:SMT.Workflow.Engine.BLL 類方法:CallWCFService() WCF地址:" + endaddress + "方法名稱:" +funcName + " " +
                            "WCF協議:" + bindingName + "\r\n" +
                            "參數:" + strValue + "\r\n";
         Tracer.Debug(cMessage+e.ToString());
         erroMesssage += cMessage;
         return null;
         //throw new Exception("命名空間:SMT.Workflow.Engine.BLL 類方法:CallWCFService()" + e.Message);  //暫時不拋出異常也能往下走
     }
 }
開發者ID:SaintLoong,項目名稱:TMFlow,代碼行數:32,代碼來源:Utility.cs


注:本文中的System.ServiceModel.ChannelFactory.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。