Error occured in CRM 2011 and AX2009 integration through web service...System.ServiceModel.FaultException: You cannot log on to Microsoft Dynamics AX..

Answered Error occured in CRM 2011 and AX2009 integration through web service...System.ServiceModel.FaultException: You cannot log on to Microsoft Dynamics AX..

  • Thursday, November 22, 2012 10:42 AM
     
      Has Code

    Hello,

    I am trying to integrate CRM 2011 (Order) entity with AX 2009.

    For that i have made a WCF web service in which i have called AX AIF web service.

    And then i have called that WCF web service on CRM Order form save event.

    All code is fine which i am posting here but i am getting error like this.

    WCF web service code :-->

    public string HelloWorld(string OrderId, string CustAccount)
            {
                // Instantiate an instance of the service client class.
                ax.SalesOrderServiceClient proxy = new ax.SalesOrderServiceClient();
    
                // Create an instance of the document class.
                ax.AxdSalesOrder salesOrder = new ax.AxdSalesOrder();
    
                // Create instances of the entities that are used in the service and
                // set the needed fields on those entities.
                ax.AxdEntity_SalesTable salesTable = new ax.AxdEntity_SalesTable();
                salesTable.CurrencyCode = "USD";
                salesTable.CustAccount = "1101";
                salesTable.DeliveryDate = Convert.ToDateTime("2/14/2010");
                salesTable.Payment = "N060";
                salesTable.PurchOrderFormNum = "PO";
    
                ax.AxdEntity_SalesLine salesLine = new ax.AxdEntity_SalesLine();
                salesLine.ItemId = "1001";
                salesLine.SalesQty = 88;
                salesLine.SalesUnit = "ea";
    
                ax.AxdEntity_InventDim inventDim = new ax.AxdEntity_InventDim();
                inventDim.configId = "HD";
                inventDim.InventColorId = "01";
                inventDim.InventSizeId = "42";
    
                // Add the sub-entity instances to their parent entities as an array
                // of the sub-entity type.
                salesLine.InventDim = new ax.AxdEntity_InventDim[1] { inventDim };
                salesTable.SalesLine = new ax.AxdEntity_SalesLine[1] { salesLine };
                salesOrder.SalesTable = new ax.AxdEntity_SalesTable[1] { salesTable };
    
                try
                {
                    // Call the create method on the service passing in the document.
                    ax.EntityKey[] returnedSalesOrderEntityKey = proxy.create(salesOrder);
    
                    // The create method returns an EntityKey which contains the ID of the sales order.
                    ax.EntityKey returnedSalesOrder = (ax.EntityKey)returnedSalesOrderEntityKey.GetValue(0);
                    return string.Format("The sales order created has a Sales ID of {0}", returnedSalesOrder.KeyData[0].Value);
                }
                catch (Exception e)
                {
                    return string.Format("Error Details :- {0}",e.ToString());
                }
                //return string.Format("SalesId :- {0} and CustAccount :- {1}", SalesId, CustAccount);
                //return string.Format("Tested Successfully...");
            }

    My javascript code through which i am calling above WCF web service. :-->

    function SubmitToAxSales() 
    {
        debugger;
        var ordernumber = Xrm.Page.getAttribute("ordernumber").getValue();
        var oNameAlias = Xrm.Page.getAttribute("customerid");
        var NameAlias = "";
        if (oNameAlias != null) 
        {
            var lookUpObjectValue = oNameAlias.getValue();
            if (lookUpObjectValue != null) 
            {
                var NameAlias = lookUpObjectValue[0].name;
            }
        }
        //alert(ordernumber);
        //alert(NameAlias);
    
        ////Submit Sales Order
     
        //var xml = "SalesId="+ ordernumber +"&CustAccount="+ NameAlias +"";
        var xml ="" +
          "<?xml version='1.0' encoding='utf-8'?>" +
          "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
          "<soap:Body>" +
          "<HelloWorld xmlns='http://tempuri.org/'>" +
          "<SalesId>" + ordernumber + "</SalesId>" +
          "<CustAccount>" + NameAlias + "</CustAccount>" +
          "</HelloWorld>" +
          "</soap:Body>" +
          "</soap:Envelope>";
        //alert(xml);
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttp.open("POST", "http://<<myIP>>:5555/HelloWorldTest/Service1.svc", false); 
        xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttp.setRequestHeader("Content-Length", xml.length);
        xmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/IService1/HelloWorld");
        xmlHttp.send(xml);
    
        var resultXml2 = xmlHttp.responseXML;
        //alert(resultXml2);
        if (resultXml2.text == "Unable to connect to the remote server") 
        {
            alert("Unable to connect to the remote server");
        }
        else
        {
            alert("Record Submitted to AX");
        }
    }

    My error details is as below...

    Error Details :- System.ServiceModel.FaultException: You cannot log on to Microsoft Dynamics AX.. Error details: You are not a recognized user of Microsoft Dynamics AX. Contact your system administrator for help.. Check the Web server event viewer for more information, or contact your Administrator.
    
    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 TestHelloWorld.AXServiceReference.SalesOrderService.create(SalesOrderServiceCreateRequest request)
       at TestHelloWorld.AXServiceReference.SalesOrderServiceClient.TestHelloWorld.AXServiceReference.SalesOrderService.create(SalesOrderServiceCreateRequest request) in E:\New folder\TestHelloWorld\TestHelloWorld\Service References\AXServiceReference\Reference.cs:line 11052
       at TestHelloWorld.AXServiceReference.SalesOrderServiceClient.create(AxdSalesOrder SalesOrder) in E:\New folder\TestHelloWorld\TestHelloWorld\Service References\AXServiceReference\Reference.cs:line 11058
       at TestHelloWorld.Service1.HelloWorld(String OrderId, String CustAccount) in E:\New folder\TestHelloWorld\TestHelloWorld\Service1.svc.cs:line 70

    What is the problem.. I do not understand AX..

    Please Help.


All Replies

  • Tuesday, December 04, 2012 6:33 AM
     
     Answered Has Code

    Hi All,

    I have resolved this issue by providing CRM credentials in code.

    Here is the code for those who are having the same error...

    Just put this code above all...

    ax.SalesOrderServiceClient sc = new ax.SalesOrderServiceClient();
                sc.ClientCredentials.Windows.ClientCredential.UserName = "crmuser";
                sc.ClientCredentials.Windows.ClientCredential.Password = "crm@password";
    
                sc.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

    This will resolve above error.

    • Marked As Answer by Dynamics CRM 31 Tuesday, December 04, 2012 6:34 AM
    •