如何在配置文件中设置 WCF 的身份验证

本文关键字:WCF 身份验证 设置 配置文件 | 更新日期: 2023-09-27 18:31:06

有谁知道如何在配置文件中设置 WCF 的身份验证?

例:

我有WCF来接受用户的请求,用户只需要通过下面的URL传入变量:

http://localhost/test/username/password/

WCF 可以基于此来检查是接受还是拒绝请求。

我在配置文件下编写了以下代码,但不知何故它不起作用

如何在配置文件中设置 WCF 的身份验证

<services>
  <service behaviorConfiguration="ServiceBehavior" name="Service">
    <endpoint address="" binding="basicHttpBinding"
        name="BasicHttpEndpoint"
        bindingConfiguration=""
        contract="IService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding"
       contract="IMetadataExchange" />
  </service>
</services> 

包含行为规范的示例:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="EndpointAjaxBehaviorName">
                <enableWebScript />
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviorName" >
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceAuthorization impersonateCallerForAllOperations="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
        <service name="ServiceName" 
                    behaviorConfiguration="ServiceBehaviorName">
            <endpoint address="" behaviorConfiguration="EndpointAjaxBehaviorName"
             binding="webHttpBinding" contract="YourServiceOrInterface" />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </service>
    </services>
</system.serviceModel>

如果你想使用Ajax,"enableWebScript"是必需的