5

I have a WCF service (AIF) on Microsoft Dynamics AX

I can call it without any problem using .NET 4.6.1. However, when I run the same exact code using .NET Core I get an error which states

A call to SSPI failed The target principal name is incorrect

enter image description here

There are many alike questions out there about this error but the solutions does not fix my problem.

    var service = new MarketplaceGetItemsDataServiceClient();
    service.ClientCredentials.Windows.ClientCredential.UserName = "UserName";
    service.ClientCredentials.Windows.ClientCredential.Password = "P@ssword";
    service.ClientCredentials.Windows.ClientCredential.Domain = "Domain";
    var result = service.GetItemsDataAsync(new CallContext(), new SearchOptionsDC() { VendorId = "0000" }).Result;
Mehrdad Kamelzadeh
  • 1,614
  • 2
  • 19
  • 36

2 Answers2

4

In Connected Services\MyService\Rference.cs file find the method GetEndpointAddress() and add the UpnEndpointIdentity with your identity account.

private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
    {
        if ((endpointConfiguration == EndpointConfiguration.NetTcpBinding_MyService))
        {
            return new System.ServiceModel.EndpointAddress(
                new System.Uri(@"net.tcp://190.188.1.2:8201/DynamicsAx/Services/MyService"), 
                new System.ServiceModel.UpnEndpointIdentity("host@host.com")
                );
        }
        throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
    }
panicoper
  • 1,014
  • 1
  • 12
  • 15
  • Please add code and data as text ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](//meta.stackoverflow.com/a/285557). In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. – Dharman Sep 02 '19 at 15:34
1

Change the DNS and replace it with the IP in the WCF tool.

Necoras
  • 4,563
  • 1
  • 16
  • 44
naojamg
  • 11
  • 2
  • 1
    Can you please read this: https://stackoverflow.com/help/how-to-answer and edit your answer? – RtmY Mar 08 '19 at 19:14
  • Can you explain why this workaround works, and maybe point me at some documentation about this ? We have this issue, but can't really use IP addresses. – MultiMat Feb 20 '20 at 14:01