//得到服务配置信息 private static MB.Util.Model.WcfCredentialInfo createClientConfigInfo(MB.Util.Model.ServerConfigInfo serverInfo) { if (serverInfo.Credential.IndexOf(':') >= 0) { MB.Util.Model.WcfCredentialInfo newInfo = new MB.Util.Model.WcfCredentialInfo(); newInfo.BaseAddress = serverInfo.Credential; newInfo.HostType = MB.Util.Model.WcfServiceHostType.DEVELOPER; return(newInfo); } else { string creName = serverInfo.Credential; string fileFullName = AppDomain.CurrentDomain.BaseDirectory + serverInfo.Credential; if (!System.IO.File.Exists(fileFullName)) { MB.Util.TraceEx.Write(string.Format("证书文件{0} 找不到", fileFullName)); throw new MB.Util.APPException("对应选择的服务器还没有注册相应的安全访问证书,请联系系统管理员", APPMessageType.DisplayToUser); } try { System.IO.StreamReader r = new System.IO.StreamReader(fileFullName); string txt = r.ReadToEnd(); r.Close(); r.Dispose(); string dStr = MB.Util.DESDataEncrypt.DecryptString(txt); MB.Util.Serializer.EntityXmlSerializer <MB.Util.Model.WcfCredentialInfo> ser = new MB.Util.Serializer.EntityXmlSerializer <MB.Util.Model.WcfCredentialInfo>(); return(ser.SingleDeSerializer(dStr, string.Empty)); } catch (Exception ex) { throw new MB.Util.APPException(string.Format("证书文件{0} 不是有效的证书!", fileFullName), APPMessageType.DisplayToUser, ex); } } }
/// <summary> /// 创建带有Windows 安全访问Wcf 客户端代理。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="clientRule"></param> /// <param name="serverInfo"></param> /// <returns></returns> public static T CreateWcfClient <T>(object clientRule, MB.Util.Model.ServerConfigInfo serverInfo) where T : class { return(CreateWcfClient <T>(clientRule, createClientConfigInfo(serverInfo))); }