簡體   English   中英

WCF配置文件413-請求實體太大

[英]WCF config file 413-request-entity-too-large

我已經閱讀了多個類似的主題,但仍然不知道該怎么做。 我已經創建了簡單的WCF服務,該服務正在獲取一些xml數據(以字符串形式),直到項目在Windows 7上運行之前,一切都正常運行。

413請求實體太大

我試圖將這兩個參數添加到WCF服務上的web.config中

  maxBufferSize="2147483647"    
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

有人可以看看我的配置並嘗試幫助我嗎?

WCF服務代碼:

 public class Service1 : IService1
    {
        public static Konfiguracja config;
        public static DBqueries queries;
        public void WczytajKonfiguracje()
        {
            config = new Konfiguracja();
            queries = new DBqueries();
        }
        public bool? DodajInfoSprzet(int idKlienta, string haslo, int id_zgloszenia, string HardwareInfoXML, string SoftInfoXML)
        {
         ...and some code
        }
}

這是我的wcf web.config文件:

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="ProjektSerwisConnectionString" connectionString="Data Source=.\sql12;Initial Catalog=ProjektSerwis;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647"
      maxReceivedMessageSize="2147483647"  />
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- 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 -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
  </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>

(我已經通過web.config文件中的visual studio上下文菜單對其進行了編輯)

WCF服務已通過運行

namespace SelfService
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:55555/WcfStart/");
            ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress);

            try { 
            selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "WmiService");
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            selfHost.Description.Behaviors.Add(smb);
            selfHost.Open();
            while(true)
            { 
                Console.WriteLine("Usługa działa");
                Console.WriteLine("Wpisz quit aby zakończyć działanie");
                string command = string.Empty;
                command=Console.ReadLine();
                if (String.Equals(command.ToLower(), "quit".ToLower()))
                        break;
            }
                // Close the ServiceHostBase to shutdown the service.  
                selfHost.Close();
            }
            catch (CommunicationException ce)  
            {  
                Console.WriteLine("An exception occurred: {0}", ce.Message);  
                selfHost.Abort();  
            }
}
    }
}

並且客戶端僅引用了Web服務,並通過以下方式進行連接:

  Service1Client scl = new Service1Client();
            bool? ok = false;
            try
            {
                ok = scl.DodajInfoSprzet(IdKlienta, haslo, IdZgloszenia, HardwareInfoXML, SoftInfoXml);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

我知道我已經粘貼了很多代碼,但是我不知道該如何處理我的web.config文件

正在發送的數據不大,小於1 MB

您是否只是將此配置放在web.config中?

由於將WCF托管為控制台應用程序,因此必須在托管應用程序的App.config中進行配置。

暫無
暫無

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

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