簡體   English   中英

413實體太大異常,WCF服務

[英]413 Entity too large exception, wcf service

我的代碼因以下異常而崩潰:

mscorlib.dll中發生了類型為'System.ServiceModel.ProtocolException'的未處理異常

附加信息:遠程服務器返回了意外的響應:(413)請求實體太大。

這是我的web.config文件:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>

    <behaviors>  
      <serviceBehaviors>  
        <behavior name="WcfService1.Service1Behavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                    customUserNamePasswordValidatorType="WcfService1.CustomValidator, WcfService1"/>                                                            
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>  
    </behaviors>

    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior" >
        <endpoint address="wsHttp" binding="wsHttpBinding" contract="WcfService1.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses >
            <add  baseAddress="http://localhost/Service1.svc/wsHttp"/>
          </baseAddresses>
        </host>
      </service>
    </services>

    <bindings>       
      <wsHttpBinding>          
        <binding name="SafeServiceConf" maxReceivedMessageSize="2147483647">             
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />             
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>          
         </binding>       
      </wsHttpBinding>    
    </bindings>



    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  
  </system.serviceModel>  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

這是我的客戶端app.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="WindowsFormsApplication.Properties.Settings.TestTestConnectionString" connectionString="Data Source=;Initial Catalog=TestTest;Persist Security Info=True;User ID=;Password=" providerName="" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <system.serviceModel>

    <client>
      <endpoint address="http://localhost/Service1.svc/wsHttp"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
        contract="ServiceReference2.IService1" name="WSHttpBinding_IService1">
        <identity>
          <userPrincipalName value="Administrator" />
        </identity>
      </endpoint>
    </client>

    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService1" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我沒看到什么?

在此先感謝您的幫助。

一個問題是,您永遠不會將在服務配置中定義的綁定分配給端點,因此服務將使用wsHttpBinding的默認值。 嘗試通過bindingConfiguration屬性將“ SafeServiceConf”綁定配置分配給端點:

<endpoint address="wsHttp" 
          binding="wsHttpBinding"
          bindingConfiguration="SafeServiceConf"
          contract="WcfService1.IService1" />

然后,服務將使用您指定的值,而不是默認值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM