3

我有一个非常简单的 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>
4

2 回答 2

0

您是否缺少端点行为?

behaviorConfiguration="WebHttpEndpointBehavior"

<endpointBehaviors>
        <behavior name="WebHttpEndpointBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
于 2016-04-28T06:25:42.607 回答
-3

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

于 2014-10-10T07:15:56.797 回答