我有一个非常简单的ServiceAuthorizationManager(也许是最简单的),并且在网络上关注了各种教程,但是由于某些原因,我的断点都没有命中,这导致我认为它没有被调用。
创建了一个名为WcfTest的WCF服务应用程序
保留默认类Service1.svc,IService.cs,但更改了方法以返回字符串
添加了一个新类,该类继承自ServiceAuthorizationManager
重写方法CheckAccessCore()
调整了web.config,使其使用此管理器类
运行WCF服务应用程序
程序集称为WcfTest
所有类都位于项目的根目录中,没有文件夹或任何东西
调用该方法,此时我希望调用ServiceAuthorizationManager还是在这里出错?我以为它的全部目的是在收到每个请求时都点击自定义ServiceAuthorizationManager?
在此先感谢,Onam。
所需的任何其他信息都让我知道,当这显然很简单时,我会非常困惑,因为我非常困惑。
[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>
最佳答案
您是否缺少端点行为?
behaviorConfiguration="WebHttpEndpointBehavior"
<endpointBehaviors>
<behavior name="WebHttpEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
关于c# - 未调用ServiceAuthorizationManager,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17831542/