Beispiel #1
0
 protected void OpenSession()
 {
     if (session == null || !(session.State == CommunicationState.Opened))
     {
         NetTcpBinding   binding = GetTcpBinding();
         EndpointAddress address = new EndpointAddress(string.Format("net.tcp://localhost:2660/CoreService/2011/netTcp", Environment.MachineName));
         session = new SessionAwareCoreServiceClient(binding, address);
     }
     session.Open();
 }
        /// <summary>
        /// Initialize the CoreService Context
        /// </summary>
        /// <param name="endpointUri"></param>
        /// <param name="windowsNetworkCredentials"></param>
        public CoreServiceFrameworkContext(Uri endpointUri, NetworkCredential windowsNetworkCredentials)
        {
            _endpointUri = endpointUri;

            //Dynamically instantiate the correct binding from the Abstract method that each implementing class will provide.
            var endpointBinding = this.GetBinding();

            //Create the Endpoint Address for WCF
            var endpointAddress = new EndpointAddress(endpointUri);

            //Initialize the Client Proxy and the NetworkCredentials for Connection, if NetworkCreditials are null then skip
            //and allow .Net to process with defaults.
            _client = new SessionAwareCoreServiceClient(endpointBinding, endpointAddress);

            //Implement Optimizations for the Service connection shared by all Implementations
            //NOTE:  If specified then implement NetworkSecurity Credentials
            if (windowsNetworkCredentials != null)
            {
                _client.ChannelFactory.Credentials.Windows.ClientCredential = windowsNetworkCredentials;
            }

            //NOTE:  Implement optimizations for WCF Client Connection
            //       See this Blog for more info. on WCF Optimization: http://blog.shutupandcode.net/?p=1085
            if (_client.State == CommunicationState.Created)
            {
                _client.Open();
            }
        }
        protected CoreServiceFrameworkContext(Uri endpointUri, NetworkCredential windowsNetworkCredentials)
        {
            _endpointUri = endpointUri;
            var endpointBinding = this.GetBinding();

            var endpointAddress = new EndpointAddress(endpointUri);

            _client = new SessionAwareCoreServiceClient(endpointBinding, endpointAddress);

            if (windowsNetworkCredentials != null)
            {
                _client.ChannelFactory.Credentials.Windows.ClientCredential = windowsNetworkCredentials;
            }

            if (_client.State == CommunicationState.Created)
            {
                _client.Open();
            }
        }