简体   繁体   中英

how can I set the authentication for WCF in the config file?

Does anyone know how can I set the authentication for WCF in the config file?

Example:

I have the WCF to accept the request from the user, user just need to pass in the variable through the URL below:

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

and the WCF can based on this to check whether to accept or reject the request.

I wrote the following code under the config file, but somehow it's not working

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

example including behaviour specifications:

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

"enableWebScript" is necessary if you want to use Ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM