WCF禁用匿名身份验证

时间:2015-09-03 12:02:56

标签: c# .net wcf iis web-config

我实际上对WCF有一点问题。一切都很好,除了当我在IIS上禁用Aninymous身份验证时,没有返回任何结果。我没有写这个代码,而是来自一个离开公司的同事。 这是WCF的Web.Config形式:

    <?xml version="1.0"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="Error.svclog"/>
    </sharedListeners>
  </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <uri>
    <schemeSettings>
      <clear/>
      <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
      <add name="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
    </schemeSettings>
  </uri>
  <system.net>
    <settings>
      <httpListener unescapeRequestUrl="false"/>
    </settings>
  </system.net>
  <system.web>
    <httpRuntime maxQueryStringLength="2048" maxUrlLength="4000" requestPathInvalidCharacters="" requestValidationMode="2.0" targetFramework="4.5"/>
    <pages validateRequest="false"/>
    <compilation targetFramework="4.5" debug="true"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MetadataBehavior">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="https" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="MetadataBehavior" name="MyWCF.MyService">
        <!-- Configuration HTTPS-->

        <!--<endpoint address="SoapSecure" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyWCF.IMyService"/>
        <endpoint behaviorConfiguration="RestBehavior" binding="webHttpBinding" bindingConfiguration="https" name="REST" contract="MyWCF.IMyService"/>-->

        <!-- Configuration HTTP-->
        <endpoint address="Soap" binding="basicHttpBinding" bindingConfiguration="" contract="MyWCF.IMyService"/>
        <endpoint behaviorConfiguration="RestBehavior" binding="webHttpBinding" bindingConfiguration="" name="REST" contract="MyWCF.IMyService"/>

      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <security>
      <requestFiltering allowDoubleEscaping="true"/>
    </security>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        Pour parcourir le répertoire racine de l'application Web lors du débogage, définissez la valeur ci-dessous sur true.
        Définissez-la sur false avant le déploiement pour ne pas divulguer d'informations du dossier de l'application Web.
      -->
    <directoryBrowse enabled="true"/>
    <!-- MK 27/10/2014: Access control same origin hotfix-->
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

现在,解决这个问题对客户来说至关重要,所以我非常感谢建议和任何帮助。

感谢您的时间

1 个答案:

答案 0 :(得分:0)

如果要禁用匿名身份验证,还必须将clientCredentialType设置为None

    <security mode="Transport">
        <transport clientCredentialType="None" />
    </security>