0

Windows認証を使用したWCFサービスがあります。別のサーバーにデプロイした後、次の例外を受け取りました。

System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized

クライアント構成は変更されず、次のようになります。

<ws2007HttpBinding>
  <binding name="autoSecureBinding">
    <security mode="TransportWithMessageCredential">
      <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""></transport>
      <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="false"/>
    </security>
  </binding>
</ws2007HttpBinding>

編集: ブラウザでサービスを開くと、次のエラーが表示されます。

Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

何が問題なのか誰か知っていますか?

4

2 に答える 2

0

同じ Active Directory ドメインの下に別のサーバーがありますか?

また、ターゲット IIS に移動し、サイト/アプリケーション認証設定で「Windows 認証」が「有効」に設定されているかどうかを確認します。(以下の IIS7 の画面を参照してください) 認証設定アイコン

ウィンドウ認証を有効にする

于 2013-06-06T09:33:27.967 に答える
0

これは、私が使用している Win 認証のみの WCF サービスの有効な web.config です (IIS では Windows 認証のみが有効になっています)。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true" />
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <bindings>
            <basicHttpBinding>
                <binding name="MyBindingForWindowsAuth">
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Ntlm" />
                        <!--<transport clientCredentialType="Windows" />-->
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <services>
            <service name="DataAccessService.Service">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBindingForWindowsAuth" contract="DataAccessService.IService" />
                <endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="MyBindingForWindowsAuth" contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" />
    </system.webServer>
</configuration>

この設定が整っている場合、ASP.NET ユーザー ID を WCF に渡したい場合は、次の 3 つのオプションがあります。

オプション1:

client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("phil.morris", "P4ssW0rd", "mydomain");

オプション 2:

偽装を使用:

using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
    string s = client.GetUserInfo();
    retVal = "Wcf User: " + s;
}

オプション 3:
呼び出し元の ASP.NET アプリケーションで ASP.NET 偽装を有効にする

于 2014-01-30T19:29:43.517 に答える