IKovalchuk

The server has rejected the client credentials.

Discussion created by IKovalchuk on Sep 24, 2014
Latest reply on Sep 24, 2014 by Marcos Vainer Loeff

Time to time I have exception during accessing AF system.

 

My software starts some number of threads. In each thread connects to AF/PI servers using same network credential (user, password, domain), retrieve elements, read/write to PI server.

 

Sometimes I recieve exception about credential rejection. Full text:

 

 

 

 

 
System.ServiceModel.CommunicationException: Cannot connect to server 'PI-AF-SERVER'. ---> System.ServiceModel.Security.SecurityNegotiationException: The server has rejected the client credentia
ls. ---> System.Security.Authentication.InvalidCredentialException: The server has rejected the client credentials. ---> System.ComponentModel.Win32Exception: The logon attempt failed
   --- End of inner exception stack trace ---
   at System.Net.Security.NegoState.ProcessReceivedBlob(Byte[] message, LazyAsyncResult lazyResult)
   at System.Net.Security.NegoState.StartSendBlob(Byte[] message, LazyAsyncResult lazyResult)
   at System.Net.Security.NegoState.CheckCompletionBeforeNextSend(Byte[] message, LazyAsyncResult lazyResult)
   at System.Net.Security.NegoState.ProcessReceivedBlob(Byte[] message, LazyAsyncResult lazyResult)
   at System.Net.Security.NegoState.StartSendBlob(Byte[] message, LazyAsyncResult lazyResult)
   at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
   at System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty& remoteSecurity)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty& remoteSecurity)
   at System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream)
   at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeo
uts, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
   at OSIsoft.AF.Support.AFProxy.Reconnect(Boolean autoPrompt, Boolean raiseEvents, AFConnectionProtocol protocol, String host, Int32 port, String accountName, TimeSpan timeOut)
   --- End of inner exception stack trace ---
   at OSIsoft.AF.Support.AFProxy.Reconnect(AFCollectiveMember member, Boolean autoPrompt, Boolean raiseEvents, AFConnectionPreference preference)
   at OSIsoft.AF.Support.AFProxy.Reconnect()
   at OSIsoft.AF.Support.AFSerialProxy.GetElementList(dcElementCollections findType, dcObjectIdentity parentIdentity, dcObjectIdentity filterIdentity, AFTime queryDate, DateTime sinceDate, String startName, Int32
startIndex, AFSortField sortField, AFSortOrder sortOrder, Int32 maxCount, Boolean returnTotalCount, Boolean& fullUpdate, DateTime& lastUpdateTime, Int32& totalCount)
   at OSIsoft.AF.Asset.AFElements.LoadObjects(Int32 page, Boolean fullReload)
   at OSIsoft.AF.AFCollection`1.GetItemsPage(Int32 page, AFGetPageMode mode)
   at OSIsoft.AF.AFCollection`1.<GetEnumerator>d__0.MoveNext()
   at PIEnd.PIAFClient.FindElementByItemId(AFElement root, Guid property, Guid resource) in c:\est-astu\PIEnd\AFClient.cs:line 1127
   at PIEnd.PIAFClient.ProcessItemBrowserGetPathnamesRequest(String[] itemIdsStr) in c:\est-astu\PIEnd\AFClient.cs:line 524
   at PIEnd.PipeClientHandle.ParseMessage(String message) in c:\est-astu\PIEnd\PipeClientHandle.cs:line 371
   at PIEnd.PipeClientHandle.Serve() in c:\est-astu\PIEnd\PipeClientHandle.cs:line 80

After this exception I must terminate thread.

 

I am using explicit connection accordint to AF SDK Reference.

 

Some pieces of code:

 

 

 
        class PIAFClient
        {
                private PISystem afSysRef;
                private PISystem afSysEst;
                private PIServer piServer;
                private AFDatabase afDbRef;
                private AFDatabase afDbEst;

          public bool ConnectRef(string server, string db)
          {
               try
               {
                    if (afSysRef == null)
                         afSysRef = new PISystems()[server];

                    if (afSysRef == null)
                    {
                         Console.WriteLine("[AF CLIENT] Unknown AF system {0}", server);
                         return false;
                    }

                    if (afSysRef.ConnectionInfo.IsConnected == false)
                    {
                         NetworkCredential account = new NetworkCredential(
                              ConfigurationManager.AppSettings["AFUser"],
                              ConfigurationManager.AppSettings["AFPassword"],
                              ConfigurationManager.AppSettings["AFDomain"]);

                         afSysRef.Connect(account);
                    }

                    afDbRef = afSysRef.Databases[db];

                    if (afDbRef == null)
                    {
                         Console.WriteLine("[AF CLIENT] Unknown AF DB {0}", db);
                         return false;
                    }
               }
               catch(Exception e)
               {
                    Console.WriteLine("[AF CLIENT] {0}", e.ToString());
                    return false;
               }

               return true;
          }

 

Outcomes