Get an error when consuming a WCF server from .Net Core 2.1 but it's fine on .NET

1k views Asked by At

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;
2

There are 2 answers

2
naojamg On

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

1
panicoper On

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("[email protected]")
                );
        }
        throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
    }