0

IIS 7 で別々にホストされている 2 つの WCF サービスがあります。最初のサービスは外部から呼び出すことができ、WebHttpBindingWindows 認証を使用します。2 番目のサービスは、WsDualHttpBinding.

最初のサービスが呼び出されると、からユーザーの Windows 名を取得できますServiceSecurityContext.Current.WindowsIdentity.Name。2 番目のサービスでは、それは機能せずServiceSecurityContext.Current.WindowsIdentity.NameIIS APPPOOL\DefaultAppPool.

Windows 認証を使用するように構成しWsDualHttpBindingましたが、役に立ちませんでした。サーバー側の構成は次のとおりです。

<wsDualHttpBinding>
  <binding name="internalHttpBinding">
    <security mode="Message">
      <message clientCredentialType="Windows"/>
    </security>
  </binding>
</wsDualHttpBinding>

そして、2 番目のサービスとの通信を確立するための最初のサービスのコードは次のとおりです。

private WSDualHttpBinding binding = new WSDualHttpBinding();
private ChannelFactory<IMyService> factory;
public IMyService Contract { get; set; }
public MyServiceCallback Callback { get; set; }

public MyService(Uri uri)
{
    EndpointAddress address = new EndpointAddress(uri);
    Callback = new MyServiceCallback();
    var instanceContext = new InstanceContext(Callback);

    binding.Security.Mode = WSDualHttpSecurityMode.Message;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

    factory = new DuplexChannelFactory<IMyService>(instanceContext, binding, address);
    factory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
    factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
    Contract = factory.CreateChannel();

    // Call operations on Contract
}

ユーザーの ID を 2 番目のサービスに渡すように最初のサービスを構成するにはどうすればよいですか?

4

2 に答える 2