为什么我的WCF ServiceAuthorizationManager在每个请求上被调用两次?

时间:2014-07-25 18:34:14

标签: .net wcf authentication iis

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

Interace:

<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 个答案:

答案 0 :(得分:1)

我解决了这个问题。看起来IIS可能不喜欢我的界面中的模糊(?)uriTemplate,并且正在转发或重定向请求,或者它可能是别的,我不会再花时间调查它。我只是添加&#34; /&#34; 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/)注意&#34; /&#34;在UriTemplate:=&#34; /&#34;

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