简体   繁体   English

从.Net Core 2.1使用WCF服务器时出错,但在.NET上没问题

[英]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 我在Microsoft Dynamics AX上有一个WCF服务(AIF)

I can call it without any problem using .NET 4.6.1 . 我可以使用.NET 4.6.1毫无问题地调用它。 However, when I run the same exact code using .NET Core I get an error which states 但是,当我使用.NET Core运行相同的确切代码时,我得到一个错误

A call to SSPI failed The target principal name is incorrect 对SSPI的调用失败目标主体名称不正确

在此输入图像描述

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;

更改DNS并将其替换为WCF工具中的IP。

In Connected Services\\MyService\\Rference.cs file find the method GetEndpointAddress() and add the UpnEndpointIdentity with your identity account. 在Connected Services \\ MyService \\ Rference.cs文件中,找到方法GetEndpointAddress()并将UpnEndpointIdentity与您的身份帐户一起添加。

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));
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM