【问题标题】:ServiceAuthorizationManager not called未调用 ServiceAuthorizationManager
【发布时间】:2013-07-23 18:47:52
【问题描述】:

我有一个非常简单的 ServiceAuthorizationManager(也许是最简单的),并遵循了网络上的各种教程,但由于某种原因,我的断点都没有被命中,这导致我认为它没有被调用。

  • 创建了一个名为 WcfTest 的 WCF 服务应用程序
  • 保留默认类 Service1.svc、IService.cs 但更改方法以返回字符串
  • 添加了一个继承自 ServiceAuthorizationManager 的新类
  • 重写了方法 CheckAccessCore()
  • 调整 web.config 使其使用此管理器类
  • 运行 WCF 服务应用程序

  • 程序集称为 WcfTest

  • 所有类都位于项目的根目录中,没有文件夹或任何东西

调用该方法,此时我希望调用我的 ServiceAuthorizationManager 还是我错了?我认为它的全部目的是在收到的每个请求上点击自定义 ServiceAuthorizationManager?

提前致谢,奥南。

如果需要更多信息,请告诉我,我会像鹰一样看这个,因为当这显然很简单时,我很困惑。

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebGet(UriTemplate = "/getIt",ResponseFormat=WebMessageFormat.Json)]
    string GetIt();
}

public class Service1 : IService1
{
    public string GetIt()
    {
        return "boo!";
    }
}

public class MyServiceMan : ServiceAuthorizationManager
{
    protected override bool CheckAccessCore(OperationContext operationContext)
    {
        try
        {
            //Some stuff here breakpoint set on above line not hit
            return false;
        }
        catch (Exception e)
        {
            return false;
        }
    }
}

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfTest.Service1">
        <endpoint address=""
                  contract="WcfTest.IService1"
                  binding="webHttpBinding">
        </endpoint>
      </service>
    </services>
    <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="false"/>
          <serviceAuthorization serviceAuthorizationManagerType="WcfTest.MyServiceMan,WcfTest" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

【问题讨论】:

    标签: c# wcf soa


    【解决方案1】:

    我遇到了同样的问题。我通过在我的CustomAuthorizationManager CheckAccessCore 方法中设置断点解决了这个问题,并开始在 Visual Studio 中调试我的 WCF 项目。然后我从我的桌面 WCF 客户端应用程序运行并执行一些方法,它就完成了。

    【讨论】:

      【解决方案2】:

      您是否缺少端点行为?

      behaviorConfiguration="WebHttpEndpointBehavior"
      
      <endpointBehaviors>
              <behavior name="WebHttpEndpointBehavior">
                <webHttp />
              </behavior>
            </endpointBehaviors>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-10
        • 2016-12-12
        • 1970-01-01
        相关资源
        最近更新 更多