示例#1
0
 /// <summary>
 /// 调用服务器端一个函数,并返回一个值
 /// </summary>
 /// <typeparam name="T">返回值类型</typeparam>
 /// <param name="invoke">参数</param>
 /// <returns>返回值</returns>
 protected T Invoke <T>(WcfInvokeInfo invoke)
 {
     try
     {
         byte[] bs = CommunicationSerializer.SerializeDataContract(invoke, "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes());
         bs = Process(bs, (buffer) =>
         {
             var service = GetService();
             return(service.Process(buffer));
         });
         var result = CommunicationSerializer.DeserializeDataContract(typeof(WcfInvokeResult), "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes(), bs) as WcfInvokeResult;
         if (result != null)
         {
             if (!result.IsSuccess)
             {
                 throw new WcfException(result.ErrorMessage);
             }
             return((T)result.Data);
         }
     }
     catch (Exception ex)
     {
         if (ex.Message.IndexOf("http:") > 0)
         {
             var writer = Common.Log.LogWriterGetter.GetLogWriter();
             writer.Write("WCF连接异常", "Invoke_WCF连接异常", Common.Log.LogType.Error, "WCF连接异常", ex.ToString());
             throw new Exception("您好,目前服务器繁忙,请稍后再试!");
         }
         else
         {
             throw new Exception(ex.Message);
         }
     }
     return(default(T));
 }
示例#2
0
        /// <summary>
        /// 调用服务器端一个无返回值的函数
        /// </summary>
        /// <param name="invoke">参数</param>
        protected void InvokeViaOneWay(WcfInvokeInfo invoke)
        {
            var bs = CommunicationSerializer.SerializeDataContract(invoke, "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes());

            Process(bs, buffer =>
            {
                var service = GetService();
                service.ProcessViaOneWay(buffer);
                return(null);
            });
        }
示例#3
0
        private byte[] DoProcess(byte[] buffer)
        {
            var invoke = CommunicationSerializer.DeserializeDataContract(typeof(WcfInvokeInfo), "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes(), buffer) as WcfInvokeInfo;
            var result = DoWork(invoke);

            try
            {
                buffer = CommunicationSerializer.SerializeDataContract(result, "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes());
            }
            catch (Exception ex)
            {
                result.Data         = null;
                result.IsSuccess    = false;
                result.ErrorMessage = "序列号错误:" + ex.Message;
                result.ErrorDetail  = "序列号错误 - " + ex;
                buffer = CommunicationSerializer.SerializeDataContract(result, "Communication", "www.qcw.com", KnownTypeRegister.GetKnownTypes());
            }
            return(buffer);
        }