代码之家  ›  专栏  ›  技术社区  ›  dbones

模拟WCF

  •  3
  • dbones  · 技术社区  · 16 年前

    我有一个wcf服务,托管在IIS中,我需要它来模拟annon帐户。

    在我的WebCONFIG中

    <authentication mode="Windows"/>
    <identity impersonate ="true"/>
    

    使用VS2008测试以下内容

            public void ByRuleId(int ruleId)
            {
                try
                {
                    string user = WindowsIdentity.GetCurrent().Name;
                    string name = Thread.CurrentPrincipal.Identity.Name;
                    ........
    
                    //get the data as a string.
                    using (FileStream fs = File.Open(location, FileMode.Open))
                    using (StreamReader reader = new StreamReader(fs))
                    {
                       rawData = reader.ReadToEnd();
                    }
    
                }
                catch.....
             }
    

    这是可行的。但是,如果我添加模拟属性

      [OperationBehavior(Impersonation=ImpersonationOption.Required)]
      public void ByRuleId(int ruleId)
    

    这不适用于错误消息

    未提供所需的模拟级别,或者提供的模拟级别无效。

    在我周围戳了一下,我注意到第一条路是由Kerboros认证的,第二条路在认证类型上失败了。

    我正在使用WCF客户端工具来传递我的凭据。这似乎起作用了。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Kwal    16 年前

    检查当前线程标识的“tokenImpersonationLevel”;您需要它至少是“impersonation”,才能在运行服务的计算机上执行操作。

    通常,如果使用代理客户端,则需要设置客户端的“tokenImpersonationLevel”:

    http://www.devx.com/codemag/Article/33342/1763/page/4

        2
  •  0
  •   dbones    16 年前

    这项工作的主要目标是获得anon访问权限,即使是tho mattk的答案也是一个很大的帮助。

    我就是这么做的。

    关于WCF合同的实施,我增加了

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class TransferFile : ITransferFile
    

    在web.config中

       <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled ="true" />
    

    在这之后,我可以模仿Anon帐户

    推荐文章