Reputation: 361
I have a remote machine with AX2012 installed and in it I have built a custom service in AX2012 and I am able to use it properly in a windows console application (VS2010). But when I try to connect to the service from my own machine through a windows console application (VS2012) , it gives me the error "The server has rejected the client credentials."
My code is as follows :
ServiceReference1.TestService1Client t = new ServiceReference1.TestService1Client();
t.ClientCredentials.UserName.UserName = "vanya";
t.ClientCredentials.UserName.Password = "*******";
t.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
ServiceReference1.CallContext c = new ServiceReference1.CallContext();
c.Company = "ussi";
ServiceReference1.EventList eventss = t.getEventItems(c, "BradPSUS", "contoso.com");
The binding in my app.config is as follows :
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_TestService1" transferMode="Buffered" />
<binding name="NetTcpBinding_ItemService" />
</netTcpBinding>
</bindings>
If I add security mode = "none" in the app.config I get the following error "The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9609696'"
This same thing works perfectly on the remote machine but does not work on my machine. How do I proceed?
Upvotes: 4
Views: 3093
Reputation: 361
After a week I have found the solution. Adding the answer to help others who might face this problem in future :
Change the adapter of the service from Net.Tcp to HTTP
Change security details of service's binding by going to AX->Inbound Port->Configure.
Host the service in IIS, you have to host a service on IIS if you want to use it from other domains. This link explains the process http://technet.microsoft.com/en-us/library/gg731848.aspx
Enable only windows authentication on IIS.
Create a console application in visual studio on the same machine on which AX is installed. Add reference to the service. Your app.config should look like this :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Service1" allowCookies="true"
maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxDepth="32" maxStringContentLength="200000000"
maxArrayLength="200000000" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://******/MicrosoftDynamicsAXAif60/Test3/xppservice.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1"
contract="ServiceReference1.Service1" name="BasicHttpBinding_Service1" >
</endpoint>
</client>
</system.serviceModel>
</configuration>
Take the dll of this console application and paste it in your other machine (the one not on the same domain)
Create a console application and add reference to this dll. Use this dll to access the service.
Paste the same app.config contents.
Add these three lines in the .cs file
workListSvc.ClientCredentials.Windows.ClientCredential.Domain = "*****";
workListSvc.ClientCredentials.Windows.ClientCredential.UserName = "kevin";
workListSvc.ClientCredentials.Windows.ClientCredential.Password = "*****";
Should work now.
Upvotes: 1