簡體   English   中英

WCF服務身份驗證失敗

[英]WCF service authentication fails

我正在嘗試在控制台應用程序中使用WCF服務。 我的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>

控制台應用程序代碼使身份驗證成為一部分。

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

一切對我來說似乎還可以,但它總是會引發錯誤

The caller was not authenticated by the service.

任何人都可以指出我所缺少的嗎?

1轉到“客戶項目屬性”。

一種。 轉到服務標簽

啟用此設置並使用身份驗證模式窗口

2使用這兩個示例行在客戶端項目中更改app.config文件

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

3在服務項目中更改app.config文件

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

創建服務實例並調用服務時,客戶端代碼中的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