web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX 2009 Web service access issue from WCF code of VS 2010

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am facing a problem with accessing AX 2009 web service from .NET 2010.

I created a custom web service from AX 2009.

Created a WCF project and make a reference of the service.

Now I have writted the following code :

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using Axservice1.AXServiceRef1 ;

using SysSvcmodChan =System.ServiceModel.Channels;

using SysSvcmod = System.ServiceModel;

 

namespace Axservice1

{

    class Program

    {

        static void Main(string[] args)

        {

            Axservice1.AXServiceRef1. AlarsTestqueryServiceClient a =new  Axservice1.AXServiceRef1.TestqueryServiceClient();

            AxdTestquery b = new AxdTestquery();

                      

            

            QueryCriteria q = new QueryCriteria();

            CriteriaElement[] qe = { new CriteriaElement() };

            EntityKey[] entitykey = { new  EntityKey() };

 

         

            a.ClientCredentials.Windows.ClientCredential.UserName = "xyz";

            a.ClientCredentials.Windows.ClientCredential.Password = "abc";

            a.ClientCredentials.Windows.ClientCredential.Domain = "domain1";

            a.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

 

            b.SenderId = "test";

            qe[0].DataSourceName = "Book1";

            qe[0].FieldName = "BookID";

            qe[0].Operator = Operator.Equal;

            qe[0].Value1 = "111";

            q.CriteriaElement = qe;

            Console.WriteLine("Start");

            entitykey = a.findKeys(q);

           

            if (null == entitykey)

            {

                Console.WriteLine("No Record Found");

            }

            else

            {

                Console.WriteLine(entitykey.First().KeyData[1].Field);

                Console.WriteLine(entitykey.First().KeyData[1].Value);

            }

            Console.WriteLine("Finish");

 

            Console.WriteLine("Press any key to Continue........");

            a.Close();

         }

    }

}

 Problem :

While executing I am getting the following error :

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.

I am using <basicHttpBinding> in my service.

I am using following in my web.ini file:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingWindowsAuth">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
   
    <services>
      <service behaviorConfiguration="serviceBehaviorConfiguration"
        name="Microsoft.Dynamics.IntegrationFramework.Service.TestqueryService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingWindowsAuth"
          bindingNamespace="http://schemas.microsoft.com/dynamics/2008/01/services"
          contract="Microsoft.Dynamics.IntegrationFramework.Service.TestqueryService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehaviorConfiguration">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

 

Please help.

Thanks and Regards,

Arindam

*This post is locked for comments

I have the same question (0)
  • akuehn Profile Picture
    1,995 on at

    Hi,

    can you access the webservice when you are not setting the ClientCredentials?

    If this works, the problem could be the way you are setting the credentials.

    Please try to use networkCredentials insted of WindowsCredentials. Had a similar problem in the past and useing NetworkCredentials class was the resolution.

    But at first, please make sure that you can call the service when you are not setting the Credentials "manually".

  • Community Member Profile Picture
    on at

    Hi,

    I can access the webservice even when I am not setting client credentials. Even I tried with both Windows and Network Credentials.

    It is not giving me any compilation error. I am getting the error at the following line -

    entitykey = a.findKeys(q);

    "The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'."

    Could this error because of any IIS issue or am I missing any configuration while creating the web service in AX 2009 ?

  • akuehn Profile Picture
    1,995 on at

    Ok, so i think this is not a general problem with your service itself.

    When you connect to the webservice whithout setting the credentials, wcf automatically uses the credentials of your current user account logged on to windows.

    Normally i would say that this should work:

    client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");  

    client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification;

    But please check the settings of the webservice inside the IIS. Is windows autentication enabled?

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Akuehn,

    Thank you very much for your feedback on the solution.

    I am able to sort out the problem. Firstly there were configuration issue in the IIS. Secondly I missed to provide the windows user details at Business connector Alias of AX. Thirdly chnaged configuration of the web service and it solve the issue.

    Basically it was configuration issue at IIS level.

  • vijaykumar reyya Profile Picture
    270 on at

    Hi

      I also use the same code in my application to connect Dynamics Ax 2009 service but i am getting an error

    "You cannot log on to Microsoft Dynamics AX.. Error details: Unable to log on to Microsoft Dynamics AX.. Check the Web server event viewer for more information, or contact your Administrator."

    please some one help me to fix this issue

    Thanks in advance

    Vijay

  • thuld Profile Picture
    on at

    Hello Arindam,

    could you please outline what IIS configuration are required? I am facing the same problem!

    Regards,

    Daniel

  • Community Member Profile Picture
    on at

    The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.

    I tried the same as you did..

    Can you tell me the process how to sort out

    please help me out this

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans