2

同じ web.config に ASP.NET サイトと WCF サービスを含む WebService があります。これまでは、設定することで WCF サービスで ASP.NET の偽装を使用できました。

<system.web>
    <compilation targetFramework="4.0" debug="false"/>
    <!-- switch custom errors of-->
    <identity impersonate="true"/>
    <customErrors mode="Off"/>
</system.web>

ただし、現在(他の理由で-> ASP.NET部分のCookielessセッション状態)、設定する必要があります

aspNetCompatibilityEnabled="true" 

オプションを false にします。これにより、WCF サービスに対する ASP.NET の偽装がなくなります。私の WCF サービスの 1 つは、サーバーでの IO 操作に偽装を必要とします... WCF サービス構成で直接定義することにより、以前と同じ偽装を取得する方法を知りたいです。

私が(失敗して)試したことは、設定することです

[OperationBehavior(Impersonation = ImpersonationOption.Required)]

WCF サービスでのメソッドの実装について、次に指定する

<endpoint address="" binding="wsHttpBinding" contract="IService">
  <identity>
    <servicePrincipalName value="HOST/YourMachineName" />
    <dns value="" />
  </identity>
</endpoint>

http://msdn.microsoft.com/en-us/library/ff650591.aspxで説明されているように、web.config (明らかに私のサービスの正しい値) で。

ただし、この後 WCF サービスを呼び出すことはできません... WsHttpBinding がコントラクトの ID を提供していないことがわかります。

私は何か重要なものを見逃していますか?

編集:エラーメッセージの翻訳:

: コントラクト操作 '{0}' には、自動偽装のための Windows ID が必要です。呼び出し元を表す Windows ID は、コントラクト ('{3}','{4}') のバインディング ('{1}','{2}') によって提供されません。

(元のエラー メッセージはドイツ語でした...)

4

2 に答える 2

1

これに似たものを追加してみてください

<system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="DelegationBehaviour">
                    <clientCredentials>
                        <windows allowNtlm="false" allowedImpersonationLevel="Delegation"></windows>
                    </clientCredentials>
                    <dataContractSerializer maxItemsInObjectGraph="4194304"></dataContractSerializer>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_SampleWebService" >
                    <readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192"></readerQuotas>
                    <security mode="TransportCredentialOnly">
                        <message algorithmSuite="Default" clientCredentialType="UserName"></message>
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""></transport>
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://server/WebServices/Service/Service.svc" behaviorConfiguration="DelegationBehaviour" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SampleWebService" contract="SampleWS" name="BasicHttpBinding_SampleEndpoint"></endpoint>
        </client>
    </system.serviceModel>

これはサーバー側のコードです

 <system.serviceModel>
    <services>
      <service behaviorConfiguration="CustomBehavior" name="CustomWebService">
        <endpoint address="" behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_Service" contract="WebService"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_Service" maxReceivedMessageSize="4194304" receiveTimeout="00:30:00">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CustomBehavior">
          <dataContractSerializer maxItemsInObjectGraph="4194304" ignoreExtensionDataObject="True"/>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceAuthorization impersonateCallerForAllOperations="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

これらを WebMethods で使用するだけでなく、

<WebMethod(), OperationContract(), OperationBehavior(Impersonation:=ImpersonationOption.Required)> _

私たちのために働く

于 2012-10-08T09:18:33.523 に答える
0

最終的に、バインディングで Windows 認証を使用するようにしました。

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

クライアントで特定の Windows ユーザー/パスワードの組み合わせを渡します。

channelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(@"", "", "");
channelFactory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

さらに、新しく偽装されたユーザーを Web サービスのコードで具体的に使用する必要がありました。

 using (var imp = ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
 {
     // do IO here
 }

まあ、実際の (根底にある) 疑問はまだ残っています:

ASP.NET 機能を正しくエミュレートするにはどうすればよいですか...

今のところ、この解決策には問題ありませんが、ASP.NET のなりすましに関する重要なポイントを見逃しているように感じます。

Iain に感謝します。正確な答えではありませんでしたが、少なくとも正しい道を歩むことができました。

于 2012-10-08T12:31:34.140 に答える