Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
like image 277
Mehrdad Kamelzadeh Avatar asked Jul 11 '18 07:07

Mehrdad Kamelzadeh


2 Answers

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));
    }
like image 116
panicoper Avatar answered Oct 12 '22 16:10

panicoper


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

like image 25
naojamg Avatar answered Oct 12 '22 15:10

naojamg