我有一个非常简单的ServiceAuthorizationManager(可能是最简单的),并且已经在网上学习了各种各样的教程,但由于某些原因,我的断点都没有被击中,这导致我认为它没有被调用。
运行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>
答案 0 :(得分:0)
您是否缺少端点行为?
behaviorConfiguration="WebHttpEndpointBehavior"
<endpointBehaviors>
<behavior name="WebHttpEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
答案 1 :(得分:-3)
我遇到了同样的问题。我通过在CustomAuthorizationManager CheckAccessCore
方法中设置断点并在Visual Studio中开始调试我的WCF项目来解决它。然后我从桌面WCF客户端应用程序运行并执行一些方法并完成。