restful wcf 配置web.config要点 .

1.首先是验证,配置为form形式

 

  1. <system.web>  
  2. <compilation debug="true" targetFramework="4.0" />  
  3.     <authentication mode="Forms">  
  4.         <forms loginUrl="~/Account/LogOn" timeout="2880" />  
  5.     </authentication>  
  6. t;/system.web>  

2.然后是serviceModel,其中

 

 

  1. <system.serviceModel>  
  2.       <services>  
  3.           <service behaviorConfiguration="CfxixiDataServiceBehavior" name="CfxixiDataService.EmiteDataService">  
  4.               <host>  
  5.                   <baseAddresses>  
  6.                       <add baseAddress="http://localhost:6340/CfxixiDataService/"/>  
  7.                   </baseAddresses>  
  8.               </host>  
  9.               <endpoint address="" binding="webHttpBinding" contract="CfxixiDataService.Service.IEmiteDataService" behaviorConfiguration="webBehavior" bindingConfiguration="webBinding"></endpoint>  
  10.               <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>  
  11.           </service>  
  12.       </services>  
  13.       <bindings>  
  14.           <basicHttpBinding>  
  15.               <binding name="basicHttp" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">  
  16.                   <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>  
  17.               </binding>  
  18.               <binding name="BasicTransportSecurity">  
  19.                   <security mode="Transport">  
  20.                       <transport clientCredentialType="None"/>  
  21.                   </security>  
  22.               </binding>  
  23.           </basicHttpBinding>  
  24.           <webHttpBinding>  
  25.               <binding name="webBinding" crossDomainScriptAccessEnabled="true"></binding>  
  26.           </webHttpBinding>  
  27.       </bindings>  
  28.   
  29.       <behaviors>  
  30.           <endpointBehaviors>  
  31.               <behavior name="webBehavior">  
  32.                   <webHttp/>  
  33.               </behavior>  
  34.           </endpointBehaviors>  
  35.           <serviceBehaviors>  
  36.   
  37.               <behavior name="CfxixiDataServiceBehavior">  
  38.                   <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->  
  39.                   <serviceMetadata httpGetEnabled="true"/>  
  40.                   <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->  
  41.                   <serviceDebug includeExceptionDetailInFaults="true"/>  
  42.               </behavior>  
  43.   
  44.               <behavior name="">  
  45.                   <serviceMetadata httpGetEnabled="true" />  
  46.                   <serviceDebug includeExceptionDetailInFaults="false" />  
  47.               </behavior>  
  48.           </serviceBehaviors>  
  49.     </behaviors>  
  50.     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />  
  51.   </system.serviceModel>  

3.最后是配置请求(request)

 

 

  1. <system.webServer>  
  2.    <modules runAllManagedModulesForAllRequests="true"/>  
  3.  </system.webServer>  

附配置源码:

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.   For more information on how to configure your ASP.NET application, please visit  
  4.   http://go.microsoft.com/fwlink/?LinkId=152368  
  5.   -->  
  6. <configuration>  
  7.   <configSections>  
  8.     <section name="oauth.requestTokenStore" type="EmiteDataService.OAuth.RequestTokenCache, EmiteODataService" />  
  9.     <section name="oauth.accessTokenStore" type="EmiteDataService.OAuth.AccessTokenCache, EmiteODataService" />  
  10.     <section name="oauth.consumerStore" type="EmiteDataService.OAuth.ConsumerCache, EmiteODataService" />  
  11.   </configSections>  
  12.   <connectionStrings>  
  13.     <add name="EmiteDbConnection" connectionString="data source=EMITEDB;initial catalog=Emite357;integrated security=True" providerName="System.Data.SqlClient" />  
  14.   </connectionStrings>  
  15.   <appSettings>  
  16.     <add key="EmiteDbConnection" value="Data Source=EmiteDB;Initial Catalog=Emite357;Integrated Security=True;" />  
  17.     <add key="ClientValidationEnabled" value="true" />  
  18.     <add key="UnobtrusiveJavaScriptEnabled" value="true" />  
  19.   </appSettings>  
  20.   <system.web>  
  21.     <compilation debug="true" targetFramework="4.0">  
  22.       <assemblies>  
  23.         <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  24.         <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  25.         <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  26.       </assemblies>  
  27.     </compilation>  
  28.     <authentication mode="Forms">  
  29.       <forms loginUrl="~/Account/LogOn" timeout="2880" />  
  30.     </authentication>  
  31.     <membership>  
  32.       <providers>  
  33.         <clear />  
  34.         <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />  
  35.       </providers>  
  36.     </membership>  
  37.     <profile>  
  38.       <providers>  
  39.         <clear />  
  40.         <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />  
  41.       </providers>  
  42.     </profile>  
  43.     <roleManager enabled="false">  
  44.       <providers>  
  45.         <clear />  
  46.         <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />  
  47.         <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />  
  48.       </providers>  
  49.     </roleManager>  
  50.     <pages>  
  51.       <namespaces>  
  52.         <add namespace="System.Web.Mvc" />  
  53.         <add namespace="System.Web.Mvc.Ajax" />  
  54.         <add namespace="System.Web.Mvc.Html" />  
  55.         <add namespace="System.Web.Routing" />  
  56.       </namespaces>  
  57.     </pages>  
  58.   </system.web>  
  59.   <system.webServer>  
  60.     <validation validateIntegratedModeConfiguration="false" />  
  61.     <modules runAllManagedModulesForAllRequests="true" />  
  62.   </system.webServer>  
  63.   <runtime>  
  64.     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
  65.       <dependentAssembly>  
  66.         <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />  
  67.         <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />  
  68.       </dependentAssembly>  
  69.     </assemblyBinding>  
  70.   </runtime>  
  71.   <system.serviceModel>  
  72.     <services>  
  73.       <service behaviorConfiguration="EmiteDataServiceBehavior" name="EmiteDataService.Service.EmiteDataService">  
  74.         <host>  
  75.           <baseAddresses>  
  76.             <add baseAddress="http://localhost:1234/EmiteDataService/"/>  
  77.           </baseAddresses>  
  78.         </host>  
  79.         <endpoint address="" binding="webHttpBinding" contract="EmiteDataService.Service.IEmiteDataService" behaviorConfiguration="webBehavior" bindingConfiguration="webBinding"></endpoint>  
  80.         <!--<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="EmiteDataService.Service.IEmiteDataService">  
  81.           <identity>  
  82.             <dns value="localhost"/>  
  83.           </identity>  
  84.         </endpoint>-->  
  85.         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>  
  86.       </service>  
  87.     </services>  
  88.     <bindings>  
  89.       <basicHttpBinding>  
  90.         <binding name="basicHttp" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00">  
  91.           <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>  
  92.         </binding>  
  93.         <binding name="BasicTransportSecurity">  
  94.           <security mode="Transport">  
  95.             <transport clientCredentialType="None"/>  
  96.           </security>  
  97.         </binding>  
  98.       </basicHttpBinding>  
  99.       <webHttpBinding>  
  100.         <binding name="webBinding" crossDomainScriptAccessEnabled="true"></binding>  
  101.       </webHttpBinding>  
  102.     </bindings>  
  103.   
  104.     <behaviors>  
  105.       <endpointBehaviors>  
  106.         <behavior name="webBehavior">  
  107.           <webHttp/>  
  108.         </behavior>  
  109.       </endpointBehaviors>  
  110.       <serviceBehaviors>  
  111.           
  112.         <behavior name="EmiteDataServiceBehavior">  
  113.           <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->  
  114.           <serviceMetadata httpGetEnabled="true"/>  
  115.           <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->  
  116.           <serviceDebug includeExceptionDetailInFaults="false"/>  
  117.         </behavior>  
  118.           
  119.         <behavior name="">  
  120.           <serviceMetadata httpGetEnabled="true" />  
  121.           <serviceDebug includeExceptionDetailInFaults="false" />  
  122.         </behavior>  
  123.       </serviceBehaviors>  
  124.     </behaviors>  
  125.     <serviceHostingEnvironment aspNetCompatibilityEnabled="true"  
  126.       multipleSiteBindingsEnabled="true"  />  
  127.       
  128.   </system.serviceModel>  
  129.     
  130.   <!--<startup>  
  131.     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>  
  132.   </startup>-->  
  133. </configuration>  


posted @ 2011-12-03 19:04  therockthe  阅读(2577)  评论(1)    收藏  举报