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

时间:2013-09-13 05:57:08

标签: c# .net wcf

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

示例:

我让WCF接受来自用户的请求,用户只需要通过以下URL传递变量:

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

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

我在配置文件下编写了以下代码,但不知何故它无法正常工作

                      

2 个答案:

答案 0 :(得分:0)

<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> 

答案 1 :(得分:0)

示例包括行为规范:

<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”是必需的