Consuming ax2012 services in a Windows console application

I have a remote machine with AX2012 installed, and in it I created a user service in AX2012, and I can use it correctly in the Windows console application (VS2010). But when I try to connect to the service from my own machine through the Windows console application (VS2012), it gives me the error "Server rejected 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" to app.config, I get the following error: "The socket connection was interrupted. This may be due to an error processing your message or the reception time-out by the remote host or the main network resource. The local time- socket out was "00: 00: 59.9609696" "

The same thing works fine on a remote machine, but does not work on my machine. How can I continue?

+4
source share
1 answer

A week later I found a solution. Adding an answer to help others who may encounter this problem in the future:

  • Change the service adapter from Net.Tcp to HTTP

  • Modify the service binding security data by going to AX-> Inbound Port-> Configure. enter image description here

  • To accept the service in IIS, you need to host the service in 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 in IIS. enter image description here

  • Create a console application in visual studio on the same machine where AX is installed. Add a link 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 on another computer (one that is not in the same domain)

  • Create a console application and add a link to this DLL. Use this DLL to access the service.

  • Paste the same contents of app.config.

  • Add these three lines to the .cs file

      workListSvc.ClientCredentials.Windows.ClientCredential.Domain = "*****"; workListSvc.ClientCredentials.Windows.ClientCredential.UserName = "kevin"; workListSvc.ClientCredentials.Windows.ClientCredential.Password = "*****"; 
  • Now you need to work.

+1
source

Source: https://habr.com/ru/post/1481319/


All Articles