Wednesday, May 2, 2012

Cannot logon to Dynamics AX...getting this error when trying to consume Customer AIF service

Today, I was writing C# code to consume out of the box customer service to create customers from a CSV file. Everything worked quite ok but when the create() method of customer service was called, I got the logon failure message. Further, the event viewer gave the following information:


    Object Server 01:
    An error has occurred in the services framework.  Method: AifMessageInspector::AfterReceiveRequest.  Error: System.ServiceModel.FaultException: Failed to logon to Microsoft Dynamics AX.
   at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeSession()
   at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeContext()
   at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.Attach(OperationContext owner)
   at System.ServiceModel.ExtensionCollection`1.InsertItem(Int32 index, IExtension`1 item)
   at System.Collections.Generic.SynchronizedCollection`1.Add(T item)
   at Microsoft.Dynamics.Ax.Services.AifMessageInspector.AfterReceiveRequest(Message& request, IClientChannel channel, InstanceContext instanceContext)

 


After I looked at some blog posts, I tried to refresh the WCF services from client configuration. After applying the changes, I ran the C# code and luckily this time the Logon failure was no longer there. However, I got another exception with the following details:

System.ServiceModel.FaultException`1 was unhandled
  Message=Request Failed. See the Exception Log for details.
  Source=mscorlib
  Action=http://schemas.microsoft.com/dynamics/2008/01/services/CustomerService/createAifFaultFault
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    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 CustomerServices.ServiceReference1.CustomerService.create(CustomerServiceCreateRequest request)
       at CustomerServices.ServiceReference1.CustomerServiceClient.CustomerServices.ServiceReference1.CustomerService.create(CustomerServiceCreateRequest request) in c:\users\imran.rana\documents\visual studio 2010\Projects\CustomerServices\CustomerServices\Service References\ServiceReference1\Reference.cs:line 9063
       at CustomerServices.ServiceReference1.CustomerServiceClient.create(CallContext CallContext, AxdCustomer Customer) in c:\users\imran.rana\documents\visual studio 2010\Projects\CustomerServices\CustomerServices\Service References\ServiceReference1\Reference.cs:line 9070
       at CustomerServices.Program.Main(String[] args) in c:\users\imran.rana\documents\visual studio 2010\Projects\CustomerServices\CustomerServices\Program.cs:line 139
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

At this point, I am trying to figure out what went wrong. Readers may try the first option as they might not be getting the second exception as I am.

1 comment:

Jacob said...

Thanks for the tip about refreshing WCF configuration from the AX Client configuration tool.
It solved my login failure problem also. :)