public CrmServiceFactory() { Uri organizationUri = GetOrganizationUri(); if (string.IsNullOrWhiteSpace(CrmConnectorSection.Instance.UserName)) throw new CrmException("A value must be supplied for username in the <crmFramework> section in web.config"); if (string.IsNullOrWhiteSpace(CrmConnectorSection.Instance.Password)) throw new CrmException("A value must be supplied for password in the <crmFramework> section in web.config"); if (string.IsNullOrWhiteSpace(CrmConnectorSection.Instance.Domain)) throw new CrmException("A value must be supplied for domain in the <crmFramework> section in web.config"); IServiceManagement<IOrganizationService> serviceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(organizationUri); ClientCredentials clientCredentials = new ClientCredentials(); clientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; clientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; clientCredentials.UserName.UserName = string.Format("{0}@{1}", CrmConnectorSection.Instance.UserName, CrmConnectorSection.Instance.Domain); clientCredentials.UserName.Password = CrmConnectorSection.Instance.Password; OrganizationServiceProxy organizationServiceProxy = new OrganizationServiceProxy( serviceManagement, clientCredentials); organizationServiceProxy.EnableProxyTypes(); _organizationServiceProxy = organizationServiceProxy; }
public CRMEntityMananger() { Credentials = new ClientCredentials(); Credentials.UserName.UserName = "******"; Credentials.UserName.Password = "******"; OrganizationUri = new Uri("http://crm.pecs.co.za:5555/PECorporateServices/XRMServices/2011/Organization.svc"); }
void IChannelCredentials.SetWindowsCredential(string domain, string userName, string password, int impersonationLevel, bool allowNtlm) { lock (channelBuilderSettings) { KeyedByTypeCollection<IEndpointBehavior> behaviors = channelBuilderSettings.Behaviors; NetworkCredential newCredentials = null; if ((!String.IsNullOrEmpty(domain)) || (!String.IsNullOrEmpty(userName)) || (!String.IsNullOrEmpty(password))) { if (String.IsNullOrEmpty(userName)) { userName = ""; } System.ServiceModel.Security.SecurityUtils.PrepareNetworkCredential(); newCredentials = new NetworkCredential(userName, password, domain); } ClientCredentials channelCredentials = behaviors.Find<ClientCredentials>(); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.Windows.AllowedImpersonationLevel = (TokenImpersonationLevel)impersonationLevel; // To disable AllowNtlm warning. #pragma warning disable 618 channelCredentials.Windows.AllowNtlm = allowNtlm; #pragma warning restore 618 channelCredentials.Windows.ClientCredential = newCredentials; } }
public ClientCredentials GetCredentials(AuthenticationProviderType providerType, string domain, string username, string password) { var creds = new ClientCredentials(); switch (providerType) { case AuthenticationProviderType.Federation: case AuthenticationProviderType.LiveId: if (string.IsNullOrEmpty(domain)) { creds.UserName.UserName = username; creds.UserName.Password = password; } else { creds.UserName.UserName = string.Concat(domain, @"\", username); creds.UserName.Password = password; } break; case AuthenticationProviderType.ActiveDirectory: creds.Windows.ClientCredential = string.IsNullOrEmpty(domain) ? new NetworkCredential(username, password) : new NetworkCredential(username, password, domain); break; default: break; } return creds; }
internal GetTokenUIAsyncResult(Binding binding, IClientChannel channel, ClientCredentials credentials, AsyncCallback callback, object state) : base(callback, state) { this.credentials = credentials; this.proxy = channel; this.binding = binding; this.CallBegin(true); }
protected internal void ApplyConfiguration(ClientCredentials behavior) { if (behavior == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("behavior"); } PropertyInformationCollection properties = base.ElementInformation.Properties; if (properties["windows"].ValueOrigin != PropertyValueOrigin.Default) { this.Windows.ApplyConfiguration(behavior.Windows); } if (properties["clientCertificate"].ValueOrigin != PropertyValueOrigin.Default) { this.ClientCertificate.ApplyConfiguration(behavior.ClientCertificate); } if (properties["serviceCertificate"].ValueOrigin != PropertyValueOrigin.Default) { this.ServiceCertificate.ApplyConfiguration(behavior.ServiceCertificate); } if (properties["issuedToken"].ValueOrigin != PropertyValueOrigin.Default) { this.IssuedToken.ApplyConfiguration(behavior.IssuedToken); } if (properties["httpDigest"].ValueOrigin != PropertyValueOrigin.Default) { this.HttpDigest.ApplyConfiguration(behavior.HttpDigest); } if (properties["peer"].ValueOrigin != PropertyValueOrigin.Default) { this.Peer.ApplyConfiguration(behavior.Peer); } behavior.SupportInteractive = this.SupportInteractive; }
public BusStopDetails(ClientCredentials clientCredentials) { InitializeComponent(); ActualBusStop = new BusStop(); busStopService = new BusStopServiceClient(); busStopSecureService = new BusStopSecureServiceClient(); busStopSecureService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; busStopSecureService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; busStopTypeService = new BusStopTypeServiceClient(); busStopTypeService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; busStopTypeService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; busStopTypeSecureService = new BusStopTypeSecureServiceClient(); busStopTypeSecureService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; busStopTypeSecureService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; BusStopTypeComboBox.ItemsSource = busStopTypeService.GetAll(); OpenAllTextBoxes(); SaveButton.IsEnabled = true; EditButton.IsEnabled = false; DeleteButton.IsEnabled = false; IsAddingNewObject = true; }
public ClaimsPrincipal Validate(string userName, string password) { var binding = new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential); var credentials = new ClientCredentials(); credentials.UserName.UserName = userName; credentials.UserName.Password = password; GenericXmlSecurityToken genericToken; genericToken = WSTrustClient.Issue( new EndpointAddress(_address), new EndpointAddress(_realm), binding, credentials) as GenericXmlSecurityToken; var config = new SecurityTokenHandlerConfiguration(); config.AudienceRestriction.AllowedAudienceUris.Add(new Uri(_realm)); config.CertificateValidationMode = X509CertificateValidationMode.None; config.CertificateValidator = X509CertificateValidator.None; var registry = new ConfigurationBasedIssuerNameRegistry(); registry.AddTrustedIssuer(_issuerThumbprint, _address); config.IssuerNameRegistry = registry; var handler = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection(config); ClaimsPrincipal principal; var token = genericToken.ToSecurityToken(); principal = new ClaimsPrincipal(handler.ValidateToken(token)); Tracing.Information("Successfully requested token for user via WS-Trust"); return FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager.Authenticate("ResourceOwnerPasswordValidation", principal); }
private static ClientCredentials GetCredentials(string url, string domain, string username, string password) { ClientCredentials credentials = new ClientCredentials(); var config = ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(new Uri(url)); if (config.AuthenticationType == AuthenticationProviderType.ActiveDirectory) { NetworkCredential nc = CredentialCache.DefaultNetworkCredentials; if (!string.IsNullOrEmpty(domain) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { nc = new System.Net.NetworkCredential(username, password, domain); } credentials.Windows.ClientCredential = nc; } else if (config.AuthenticationType == AuthenticationProviderType.Federation || config.AuthenticationType == AuthenticationProviderType.LiveId || config.AuthenticationType == AuthenticationProviderType.OnlineFederation) { credentials.UserName.UserName = username; credentials.UserName.Password = password; } else if (config.AuthenticationType == AuthenticationProviderType.None) { } return credentials; }
public InfocardInteractiveChannelInitializer ( ClientCredentials credentials, Binding binding) { this.binding = binding; this.credentials = credentials; }
public static IOrganizationService GetOrgService(bool admin = false, string callerId = null, string organization = null) { ClientCredentials credential = new ClientCredentials(); if (Globals.OrganizationServiceUrl.Contains("https")) { credential.Windows.ClientCredential = admin ? new NetworkCredential(Globals.AdminUserName, Globals.AdminPassword, Globals.DomainName) : CredentialCache.DefaultNetworkCredentials; credential.UserName.UserName = Globals.DomainName + @"\" + Globals.AdminUserName; credential.UserName.Password = Globals.AdminPassword; } else { credential.Windows.ClientCredential = admin ? new NetworkCredential(Globals.AdminUserName, Globals.AdminPassword, Globals.DomainName) : CredentialCache.DefaultNetworkCredentials; } OrganizationServiceProxy orgServiceProxy = new OrganizationServiceProxy(new Uri(Globals.OrganizationServiceUrl), null, credential, null); if (!string.IsNullOrEmpty(callerId)) { orgServiceProxy.CallerId = new Guid(callerId); } return orgServiceProxy; ////credential.Windows.ClientCredential = admin ? new NetworkCredential(Globals.AdminUserName, Globals.AdminPassword, Globals.DomainName) : CredentialCache.DefaultNetworkCredentials; ////credential.UserName.UserName = Globals.DomainName + @"\" + Globals.AdminUserName; ////credential.UserName.Password = Globals.AdminPassword; ////OrganizationServiceProxy orgServiceProxy = new OrganizationServiceProxy(new Uri(Globals.OrganizationServiceUrl), null, credential, null); ////if (!string.IsNullOrEmpty(callerId)) ////{ //// orgServiceProxy.CallerId = new Guid(callerId); ////} ////return orgServiceProxy; }
public CRMInvoiceService() { Credentials = new ClientCredentials(); Credentials.UserName.UserName = "******"; Credentials.UserName.Password = "******"; OrganizationUri = new Uri(ConfigurationManager.AppSettings["OrganizationEndPointURI"]); }
public static OrganizationServiceProxy Connect() { ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["CRM"]; if (settings == null) throw new ConfigurationException("No CRM Connection String was found."); Uri uri = new Uri(settings.ConnectionString); ClientCredentials credentials = null; string user = ConfigurationManager.AppSettings["User"]; string password = ConfigurationManager.AppSettings["Password"]; if (!string.IsNullOrWhiteSpace(user)) { credentials = new ClientCredentials(); credentials.UserName.UserName = ""; credentials.UserName.Password = ""; } OrganizationServiceProxy proxy = new OrganizationServiceProxy(uri, null, credentials, null); proxy.EnableProxyTypes(typeof(Toyota.Tsusho.CRM.API.Contact).Assembly); return proxy; }
public bool connect(string serviceURL, string domainName, string userName, string password) { try { Uri organizationUri = new Uri(serviceURL); Uri homeRealmUri = null; ClientCredentials credentials = new ClientCredentials(); // set default credentials for OrganizationService credentials.Windows.ClientCredential = new NetworkCredential(userName, password, domainName); // credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null); _service = (IOrganizationService)orgProxy; //to check connection with CRM getAttributeMax("campaign", "exchangerate"); return true; } catch (InvalidOperationException) { throw new connectionException("The URI provided cannot be resolved ( " + serviceURL + " )"); } catch (SecurityNegotiationException) { throw new connectionException("The authentication failed ! Please check the credentials provided."); } catch (Exception ex) { throw new connectionException(ex.Message); } }
public async Task<bool> IsAuthenticated(PortalUser user) { string Url = ConfigurationManager.AppSettings["URL"].ToString(); string CrmConnectionString = string.Format("Url={0}; Username={1}; Password={2}", Url, user.Username, user.Password); ClientCredentials credential = new ClientCredentials(); credential.UserName.UserName = user.Username; credential.UserName.Password = user.Password; CrmConnection crmConnection = CrmConnection.Parse(CrmConnectionString); crmConnection.ClientCredentials = credential; OrganizationService service = new OrganizationService(crmConnection); QueryExpression qe = new QueryExpression("systemuser"); qe.ColumnSet = new ColumnSet(); qe.ColumnSet.AddColumn("systemuserid"); qe.ColumnSet.AddColumn("fullname"); qe.Criteria = new FilterExpression(); qe.Criteria.AddCondition("domainname", ConditionOperator.Equal, user.Username); EntityCollection collection = service.RetrieveMultiple(qe); if (collection.Entities.Count == 0) { return false; } return true; }
public BusSchedule(ClientCredentials clientCredentials) { InitializeComponent(); LineService = new LineServiceClient(); LineService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; LineService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; }
public ClientCredentialsSecurityTokenManager(System.ServiceModel.Description.ClientCredentials clientCredentials) { if (clientCredentials == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clientCredentials"); } this.parent = clientCredentials; }
public ClientCredentialsSecurityTokenManager(ClientCredentials clientCredentials) { if (clientCredentials == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clientCredentials"); } _parent = clientCredentials; }
public QuestionnaireUserControl(ClientCredentials cc) { InitializeComponent(); questionnaireService = new QuestionnaireServiceClient(); questionnaireService.ClientCredentials.UserName.UserName = cc.UserName.UserName; questionnaireService.ClientCredentials.UserName.Password = cc.UserName.Password; }
//Gets credentials for CRM access public static ClientCredentials GetCredentials(Session userSession) { ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = userSession.UserName; credentials.UserName.Password = userSession.Password; credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; return credentials; }
public static IOrganizationService GetOrganisationService(string tenant, string siteUrl) { OrganizationServiceProxy sp; Uri connectionUri = new Uri(siteUrl + (siteUrl.EndsWith("/") ? "" : "/") + tenant + "/XRMServices/2011/Organization.svc"); ClientCredentials cc = new ClientCredentials(); cc.Windows.ClientCredential = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials; sp = new OrganizationServiceProxy(connectionUri, null, cc, null); return (IOrganizationService)sp; }
public void ClientCertificate () { ClientCredentials c = new ClientCredentials (); Assert.AreEqual (true, c.SupportInteractive, "#1"); X509CertificateInitiatorClientCredential ccert = c.ClientCertificate; Assert.IsNull (ccert.Certificate, "#2"); }
/// <summary> /// Initializes a new instance of the SocketAdapterConnectionFactory class /// </summary> public SocketAdapterConnectionFactory(ConnectionUri connectionUri , ClientCredentials clientCredentials , SocketAdapter adapter) { this.clientCredentials = clientCredentials; this.adapter = adapter; this._Uri = connectionUri as SocketAdapterConnectionUri; }
private Service(Guid controlID) { ClientCredentials clntCredentials = new ClientCredentials(); clntCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("hoanht", "cc50fd77f8", "ivg.vn"); Uri orgUri = new Uri("http://srv-hndev-sp201:5555/Crm2015/XRMServices/2011/Organization.svc"); OrganizationServiceProxy orgService = new OrganizationServiceProxy(orgUri, null, clntCredentials, null); _organizationService = (IOrganizationService)orgService; _controlID = controlID; }
public BusStopControl(ClientCredentials clientCredentials) { InitializeComponent(); BusStopService = new BusStopServiceClient(); BusStopService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; BusStopService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; }
public CareerUserControl(ClientCredentials clientCredentials) { InitializeComponent(); answerOptionService = new AnswerOptionServiceClient(); answerOptionService.ClientCredentials.UserName.UserName = clientCredentials.UserName.UserName; answerOptionService.ClientCredentials.UserName.Password = clientCredentials.UserName.Password; }
/// <summary> /// Initializes a new instance of the FileAdapterConnectionFactory class /// </summary> public FileAdapterConnectionFactory(ConnectionUri connectionUri , ClientCredentials clientCredentials , FileAdapter adapter) { this.clientCredentials = clientCredentials; this.adapter = adapter; this.ConnectionUri = connectionUri as FileAdapterConnectionUri; }
protected override ClientCredentials GetCredentials() { var credentials = new ClientCredentials(); credentials.UserName.UserName = "******"; credentials.UserName.Password = "******"; return credentials; }
/// <summary> /// Initializes a new instance of the ScheduleAdapterConnectionFactory class /// </summary> public ScheduleAdapterConnectionFactory(ConnectionUri connectionUri , ClientCredentials clientCredentials , ScheduleAdapter adapter) { this.clientCredentials = clientCredentials; this.adapter = adapter; ConnectionUri = connectionUri as ScheduleAdapterConnectionUri; }
public static T CreateWcfClientWithCredential <T>() { try { if (_CurrentSelectedServerInfo == null) { throw new MB.Util.APPException("没有设置服务的配置信息!"); } MB.Util.TraceEx.Write(string.Format("开始根据 app.config 创建WCF 客户端Proxy{0}", typeof(T).FullName)); T proxy = (T)MB.Util.DllFactory.Instance.CreateInstance(typeof(T)); var cfgInfo = createClientConfigInfo(_CurrentSelectedServerInfo); ServiceEndpoint endpoint = (ServiceEndpoint)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "Endpoint"); Uri u = endpoint.Address.Uri; //暂时处理 net.tcp 的地址由配置来决定 if (string.Compare(u.Scheme, "net.tcp", true) != 0) { // string newU = u.Scheme + "://" + cfgInfo.BaseAddress.Replace("http://", "") + u.AbsolutePath; string newU = cfgInfo.BaseAddress + u.AbsolutePath; if (cfgInfo.HostType == MB.Util.Model.WcfServiceHostType.IIS) { string tempUrl = newU; if (tempUrl.LastIndexOf('/') == tempUrl.Length - 1) { tempUrl = tempUrl.Remove(tempUrl.Length - 1, 1); } if (string.Compare(tempUrl.Substring(tempUrl.Length - 4, 4), ".svc", true) != 0) { newU = tempUrl + ".svc"; } } endpoint.Address = new EndpointAddress(newU); } if (cfgInfo.StartWindowsCredential && !string.IsNullOrEmpty(cfgInfo.UserName)) { System.Net.NetworkCredential credential = MB.Util.MyNetworkCredential.CreateNetworkCredential(cfgInfo); //System.ServiceModel.ClientBase<T> clientProxy = proxy as System.ServiceModel.ClientBase<T>; //clientProxy.ClientCredentials.Windows.ClientCredential = credential; System.ServiceModel.Description.ClientCredentials clientCredentials = (System.ServiceModel.Description.ClientCredentials)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "ClientCredentials"); clientCredentials.Windows.ClientCredential = credential; } return(proxy); } catch (MB.Util.APPException aex) { throw aex; } catch (Exception ex) { throw new MB.Util.APPException("创建WCF 客户端代理出错!", APPMessageType.SysErrInfo, ex); } }
public void PassOrganizationProxyData() { OrganizationServiceProxy service = CRMHelper.getOrganizationProxy(); ServiceReference1.ProxyServiceClient Obj = new ServiceReference1.ProxyServiceClient(); System.ServiceModel.Description.ClientCredentials cred = service.ClientCredentials; string url = service.ServiceManagement.CurrentServiceEndpoint.ListenUri.ToString(); Obj.getConnectedandReturnAccountName(cred.UserName.UserName, cred.UserName.Password, url); }
/// <summary> /// 创建带有Windows 安全访问Wcf 客户端代理。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="clientRule"></param> /// <param name="credentialInfo"></param> /// <returns></returns> public static T CreateWcfClient <T>(object clientRule, MB.Util.Model.WcfCredentialInfo credentialInfo) where T : class { try { if (MB.Util.MyNetworkCredential.CurrentSelectedServerInfo == null) { throw new MB.Util.APPException("没有设置服务的配置信息!"); } WcfClientInvokeAttribute cfgAtt = getWcfInvokeAtt(clientRule.GetType(), typeof(T)); if (cfgAtt == null) { //特殊说明: 从兼容性考虑,暂时先这里处理,以后需要去掉,要独立调用 return(MB.Util.MyNetworkCredential.CreateWcfClientWithCredential <T>()); } string gzip = System.Configuration.ConfigurationManager.AppSettings[ENABLE_GZIP_MESSAGE]; bool isGZipCustomBinding = !string.IsNullOrEmpty(gzip) && string.Compare(gzip, "True", true) == 0; MB.Util.Model.WcfCredentialInfo cfgInfo = null; if (credentialInfo == null) { cfgInfo = createClientConfigInfo(MB.Util.MyNetworkCredential.CurrentSelectedServerInfo); } else { cfgInfo = credentialInfo; } if (cfgAtt.SystemCode != SystemCode.Main) { string appendDetail = cfgInfo.AppendDetails; //从主服务的credetial转化到关联系统的credential MB.Util.Model.WcfCredentialInfo cfgSubSystemInfo = resolveSubSystemCredentialInfo(cfgAtt.SystemCode, appendDetail, cfgInfo); if (cfgSubSystemInfo != null) { cfgInfo = cfgSubSystemInfo; } else { cfgAtt.SystemCode = SystemCode.Main; } } System.ServiceModel.Channels.Binding binding = createBinding(cfgInfo, isGZipCustomBinding); string uri = buildEndpointAddress(cfgInfo, cfgAtt); //如果每个调用都需要记录的话为产生很多日志,这里特处理一下。 if (!_MyInvokeCache.ContainsKey(uri)) { _MyInvokeCache.Add(uri, uri); MB.Util.TraceEx.Write(string.Format("开始根据地址{0} 创建WCF 客户端Proxy{1}", uri, typeof(T).FullName)); } System.ServiceModel.EndpointAddress address = new EndpointAddress(uri); T proxy = (T)createProxyInstance <T>(binding, address); System.ServiceModel.Description.ServiceEndpoint endPoint = (System.ServiceModel.Description.ServiceEndpoint)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "Endpoint"); object obj = typeof(System.ServiceModel.ServiceHost).Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { false, Int32.MaxValue }, null, null); IEndpointBehavior dataSerializerBehavior = obj as IEndpointBehavior; endPoint.Behaviors.Add(dataSerializerBehavior); //增加分页消息头 endPoint.Behaviors.Add(new WcfDataQueryBehavior()); //增加性能指标检测行为 string wcfMonitorEnable = System.Configuration.ConfigurationManager.AppSettings[ENABLE_WCF_PERFORMANCE_MONITOR]; bool isWcfMonitorEnable = string.IsNullOrEmpty(wcfMonitorEnable) || string.Compare(gzip, "True", true) == 0; if (isWcfMonitorEnable) { endPoint.Behaviors.Add(new MB.Util.Monitors.WcfPerformanceMonitorBehavior()); } #region 加载应用程序自定义的behavior //增加扩展的Behavior,从配置文件中读取配置的扩展Behavior //在APPSetting中每个扩展由分号隔开,类型和Assmbly之间由逗号隔开 string customerBehaviorSrc = System.Configuration.ConfigurationManager.AppSettings[CUSTOM_ENDPOINT_BEHAVIORS]; if (!string.IsNullOrEmpty(customerBehaviorSrc)) { string[] customerBehaviors = customerBehaviorSrc.Split(';'); foreach (string customerBehavior in customerBehaviors) { try { string[] beTypes = customerBehavior.Split(','); object extBehavior = DllFactory.Instance.LoadObject(beTypes[0], beTypes[1]); if (extBehavior != typeof(WcfDataQueryBehavior) && extBehavior != typeof(MB.Util.Monitors.WcfPerformanceMonitorBehavior)) { IEndpointBehavior extEndPointBehavior = extBehavior as IEndpointBehavior; endPoint.Behaviors.Add(extEndPointBehavior); } } catch (Exception ex) { MB.Util.TraceEx.Write(string.Format("加载自定义behvaior出错:{0};错误:{1}", customerBehavior, ex.ToString())); } } } #endregion if (!isGZipCustomBinding) { if (cfgInfo.StartWindowsCredential && !string.IsNullOrEmpty(cfgInfo.UserName)) { System.Net.NetworkCredential credential = MB.Util.MyNetworkCredential.CreateNetworkCredential(cfgInfo); System.ServiceModel.Description.ClientCredentials clientCredentials = (System.ServiceModel.Description.ClientCredentials)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "ClientCredentials"); clientCredentials.Windows.ClientCredential = credential; } } return(proxy); } catch (MB.Util.APPException aex) { throw aex; } catch (Exception ex) { throw new MB.Util.APPException("创建WCF 客户端代理出错!", APPMessageType.SysErrInfo, ex); } }
public static ChannelPool <TChannel> GetPool(System.ServiceModel.Description.ClientCredentials credentialsToUse) { CreateChannelPool(credentialsToUse); return(_channelPool); //throw new NotImplementedException("Need to copy over the credentials to use to our channel factory."); }
protected ClientCredentials(ClientCredentials source) { throw new NotImplementedException(); }
/// <summary> /// 根据指定的系统编号,直接寻找WCF客户端地址 /// </summary> /// <typeparam name="T">客户端代理实例</typeparam> /// <param name="relativePath">相对地址</param> /// <param name="code">系统编码</param> /// <param name="bindingCfgName">自己指定绑定的名称</param> /// <returns></returns> public static T CreateWcfClient <T>(string relativePath, SystemCode code, string bindingCfgName) where T : class { try { if (MB.Util.MyNetworkCredential.CurrentSelectedServerInfo == null) { throw new MB.Util.APPException("没有设置服务的配置信息!"); } WcfClientInvokeAttribute cfgAtt = new WcfClientInvokeAttribute(typeof(T), relativePath, code); string gzip = System.Configuration.ConfigurationManager.AppSettings[ENABLE_GZIP_MESSAGE]; bool isGZipCustomBinding = !string.IsNullOrEmpty(gzip) && string.Compare(gzip, "True", true) == 0; MB.Util.Model.WcfCredentialInfo cfgInfo = createClientConfigInfo(MB.Util.MyNetworkCredential.CurrentSelectedServerInfo); if (code != SystemCode.Main) { string appendDetail = cfgInfo.AppendDetails; //从主服务的credetial转化到关联系统的credential MB.Util.Model.WcfCredentialInfo cfgSubSystemInfo = resolveSubSystemCredentialInfo(code, appendDetail, cfgInfo); if (cfgSubSystemInfo != null) { cfgInfo = cfgSubSystemInfo; } else { code = SystemCode.Main; } } System.ServiceModel.Channels.Binding binding = createBinding(cfgInfo, isGZipCustomBinding, bindingCfgName); string uri = buildEndpointAddress(cfgInfo, cfgAtt); //如果每个调用都需要记录的话为产生很多日志,这里特处理一下。 if (!_MyInvokeCache.ContainsKey(uri)) { _MyInvokeCache.Add(uri, uri); MB.Util.TraceEx.Write(string.Format("开始根据地址{0} 创建WCF 客户端Proxy{1}", uri, typeof(T).FullName)); } System.ServiceModel.EndpointAddress address = new EndpointAddress(uri); T proxy = (T)createProxyInstance <T>(binding, address); System.ServiceModel.Description.ServiceEndpoint endPoint = (System.ServiceModel.Description.ServiceEndpoint)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "Endpoint"); object obj = typeof(System.ServiceModel.ServiceHost).Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { false, Int32.MaxValue }, null, null); IEndpointBehavior dataSerializerBehavior = obj as IEndpointBehavior; endPoint.Behaviors.Add(dataSerializerBehavior); if (!isGZipCustomBinding) { if (cfgInfo.StartWindowsCredential && !string.IsNullOrEmpty(cfgInfo.UserName)) { System.Net.NetworkCredential credential = MB.Util.MyNetworkCredential.CreateNetworkCredential(cfgInfo); System.ServiceModel.Description.ClientCredentials clientCredentials = (System.ServiceModel.Description.ClientCredentials)MB.Util.MyReflection.Instance.InvokePropertyForGet(proxy, "ClientCredentials"); clientCredentials.Windows.ClientCredential = credential; } } return(proxy); } catch (MB.Util.APPException aex) { throw aex; } catch (Exception ex) { throw new MB.Util.APPException("创建WCF 客户端代理出错!", APPMessageType.SysErrInfo, ex); } }
public void ConfigureClientCredentials(System.ServiceModel.Description.ClientCredentials creds, Type contractType) { }
protected ClientCredentials(ClientCredentials other) { if (other == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other"); if (other.userName != null) this.userName = new UserNamePasswordClientCredential(other.userName); if (other.clientCertificate != null) this.clientCertificate = new X509CertificateInitiatorClientCredential(other.clientCertificate); if (other.serviceCertificate != null) this.serviceCertificate = new X509CertificateRecipientClientCredential(other.serviceCertificate); if (other.windows != null) this.windows = new WindowsClientCredential(other.windows); if (other.httpDigest != null) this.httpDigest = new HttpDigestClientCredential(other.httpDigest); if (other.issuedToken != null) this.issuedToken = new IssuedTokenClientCredential(other.issuedToken); if (other.peer != null) this.peer = new PeerCredential(other.peer); this.getInfoCardTokenCallback = other.getInfoCardTokenCallback; this.supportInteractive = other.supportInteractive; this.securityTokenHandlerCollectionManager = other.securityTokenHandlerCollectionManager; this.useIdentityConfiguration = other.useIdentityConfiguration; this.isReadOnly = other.isReadOnly; }