【问题标题】:Get an error when consuming a WCF server from .Net Core 2.1 but it's fine on .NET从 .Net Core 2.1 使用 WCF 服务器时出错,但在 .NET 上没问题
【发布时间】:2019-09-03 00:20:51
【问题描述】:

我在 Microsoft Dynamics AX 上有 WCF 服务 (AIF)

我可以使用.NET 4.6.1 毫无问题地调用它。但是,当我使用 .NET Core 运行相同的代码时,我收到一个错误,指出

对 SSPI 的调用失败目标主体名称不正确

关于这个错误有很多类似的问题,但解决方案不能解决我的问题。

    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;

【问题讨论】:

    标签: c# wcf .net-core dynamics-ax-2012 aif


    【解决方案1】:

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

    【讨论】:

    • 请将代码和数据添加为文本 (using code formatting),而不是图像。图片:A)不允许我们复制粘贴代码/错误/数据进行测试; B) 不允许根据代码/错误/数据内容进行搜索;和many more reasons。一般来说,文本格式的代码/错误/数据>>>>作为图像的代码/错误/数据>>没有。除了代码格式的文本之外,只有在图像添加了一些重要的东西,而不仅仅是文本代码/错误/数据传达的内容时,才应该使用图像。
    【解决方案2】:

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

    【讨论】:

    • 您能否阅读以下内容:stackoverflow.com/help/how-to-answer 并编辑您的答案?
    • 你能解释一下为什么这个变通办法有效吗,也许可以给我一些关于这个的文档?我们有这个问题,但不能真正使用 IP 地址。
    猜你喜欢
    • 2020-04-11
    • 2021-11-07
    • 1970-01-01
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多