/// <summary> /// Closes the proxy used for cab contract with the StackHashService. /// </summary> private void closeCabServiceProxy() { if (m_StackHashCabClient != null) { if (m_StackHashCabClient.State == CommunicationState.Faulted) { m_StackHashCabClient.Abort(); } else if (m_StackHashCabClient.State == CommunicationState.Opened) { m_StackHashCabClient.Close(); } m_StackHashCabClient = null; } }
/// <summary> /// Creates a proxy for communicating with the StackHash service Cab contract. /// The proxy is only created once. Trying to call more than once will have no /// additionaly effect. If the service is faulted then call CloseServiceProxy /// and then call this function again. /// A proxy is faulted if... /// Proxy.State == System.ServiceModel.CommunicationState.Faulted. /// </summary> private void openCabServiceProxy() { if (m_StackHashCabClient == null) { // create custom endpoint address in code - based on input in the textbox EndpointIdentity identity = EndpointIdentity.CreateSpnIdentity(m_ServicePrincipalName); EndpointAddress epa = new EndpointAddress(new Uri(m_ServiceEndpoint + "Cabs"), identity); m_StackHashCabClient = new StackHashServices.CabContractClient("NetTcpBinding_ICabContract", epa); NetTcpBinding binding = m_StackHashCabClient.ChannelFactory.Endpoint.Binding as NetTcpBinding; binding.MaxReceivedMessageSize = m_CabContractMaxReceivedMessageSize; } else { if (m_StackHashCabClient.State != CommunicationState.Opened) { closeCabServiceProxy(); openCabServiceProxy(); } } }