简体   繁体   English

WCF服务身份验证失败

[英]WCF service authentication fails

I am trying to consume a WCF service in my console app. 我正在尝试在控制台应用程序中使用WCF服务。 My App.Config file looks like this 我的App.Config文件如下所示

<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_InventItemGroupService" />
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://mydomain.com/MicrosoftDynamicsAXAif50/inventitemgroupservice.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_InventItemGroupService"
            contract="ServiceReference1.InventItemGroupService" name="WSHttpBinding_InventItemGroupService">
            <identity>
                <userPrincipalName value="asd@as" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

Console app code to make authentication part. 控制台应用程序代码使身份验证成为一部分。

 protected ProgramClass(AifSos.InventItemGroupServiceClient inventItemGroupServiceClient) // Constructor
    {
        MInventItemGroupServiceClient = inventItemGroupServiceClient;
        // ReSharper disable once PossibleNullReferenceException
        MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.UserName = "un";
        MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.Password = "pw";
        MInventItemGroupServiceClient.ClientCredentials.Windows.ClientCredential.Domain = "domain";
    }

All seems okay for me, But it always throws an error 一切对我来说似乎还可以,但它总是会引发错误

The caller was not authenticated by the service.

Can any one point out what I am missing? 任何人都可以指出我所缺少的吗?

1 Go to your Client Project Properties. 1转到“客户项目属性”。

a. 一种。 Go to services tab 转到服务标签

Enable this settings and use authentication mode windows 启用此设置并使用身份验证模式窗口

2 change app.config file inside client project with this two sample line 2使用这两个示例行在客户端项目中更改app.config文件

      <security mode="None">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
      </security>

3 change app.config file inside service project 3在服务项目中更改app.config文件

<security mode="None">
            <message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
          </security>

4 in client code when you creating service instance and calling for a service use this line to provide login info in service pc. 创建服务实例并调用服务时,客户端代码中的4使用此行在服务pc中提供登录信息。

           Service1Client client = new Service1Client();
            client.ClientCredentials.Windows.ClientCredential.UserName = "ETLIT-1";
            client.ClientCredentials.Windows.ClientCredential.Password = "etl";
            client.ClientCredentials.Windows.AllowNtlm = false;
            client.ClientCredentials.Windows.ClientCredential.Domain = "ETLIT-1-PC";
            Console.WriteLine(client.addNumber(23, 2));

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

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