.net-为什么每次请求都会调用我的WCF ServiceAuthorizationManager两次?

我已经在服务器2k8上的IIS 7.5下运行的WCF服务中实现了ServiceAuthorizationManager。对于每个传入的请求,CheckAccessCore函数将被调用两次。第一次调用CheckAccessCore时,授权头就在那里,并且用户已经过身份验证。第二次调用CheckAccessCore时,授权头为空,身份验证显然失败。为什么会发生第二部分?内部:

<OperationContract()>

<WebInvoke(UriTemplate:="", Method:="POST", BodyStyle:=WebMessageBodyStyle.Bare)>

Function ProcessMessage(ByVal value As Stream) As Stream

web.config:

<system.serviceModel>

<bindings>

  <basicHttpBinding>

    <binding name="BasicHttpBinding_IMyDataService" />

  </basicHttpBinding>

  <webHttpBinding>

    <binding name="RestSSL"> 

      <security mode="Transport">



      </security>

    </binding>

  </webHttpBinding>

</bindings>

<client>

  <endpoint address="http://localhost/OtherSvcLib/Service1/"

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyDataService"

    contract="DataService.IMyDataService" name="BasicHttpBinding_IMyDataService" />

</client>

<services>

  <service name="MyServiceLib.MyHubSvcLib" behaviorConfiguration="gogogo">

    <endpoint address="" 

              binding="webHttpBinding" 

              bindingConfiguration="RestSSL"

              behaviorConfiguration="RestSvcBehavior" 

              contract="MyServiceLib.IMyService"> 

      <identity>

        <dns value="localhost" />

      </identity>

    </endpoint>

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    <host>

      <baseAddresses>

        <add baseAddress="https://mydomain.com/MyServiceLib/MyHub.svc" />

      </baseAddresses>

    </host>

  </service>

</services>

<behaviors>

  <serviceBehaviors>

    <behavior name="gogogo">

      <serviceAuthorization serviceAuthorizationManagerType="MyServiceLib.clsCustomAuthManager, MyServiceLib">



      </serviceAuthorization>



      <serviceMetadata httpsGetEnabled="True"/>



      <serviceDebug includeExceptionDetailInFaults="False"/>

    </behavior>

  </serviceBehaviors>

  <endpointBehaviors>

    <behavior name="RestSvcBehavior">

      <webHttp helpEnabled="true"/>

    </behavior>

  </endpointBehaviors>

</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

1个回答

  1. 我解决了这个问题。看起来可能是因为我不喜欢这个模棱两可的(?)uriTemplate在我的界面上,正在转发或重定向请求,或者可能是别的什么东西,我不会再花时间调查它了。我只是在uriTemplate和客户端的URL中添加了“/”。不起作用:(请求mydomain.com/service.svc)

    <OperationContract()>
    
    <WebInvoke(UriTemplate:="", Method:="POST", BodyStyle:=WebMessageBodyStyle.Bare)>
    
    Function ProcessMessage(ByVal value As Stream) As Stream
    
    

    起作用:(请求mydomain.com/service.svc/)注意UriTemplate中的“/”号:=“/”

    <OperationContract()>
    
    <WebInvoke(UriTemplate:="/", Method:="POST", BodyStyle:=WebMessageBodyStyle.Bare)>
    
    Function ProcessMessage(ByVal value As Stream) As Stream
    
    

    2

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>