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