简体   繁体   English

WCF配置文件413-请求实体太大

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

i have read multiple similar threads but still don't know what to do. 我已经阅读了多个类似的主题,但仍然不知道该怎么做。 I've created simple WCF service which is getting some xml data (in strings) Everything was working fine until project was running on windows 7. Now, when i try to send data from client to WCF service i get exception 我已经创建了简单的WCF服务,该服务正在获取一些xml数据(以字符串形式),直到项目在Windows 7上运行之前,一切都正常运行。

413-request-entity-too-large 413请求实体太大

i've tried to add these two parameters to my web.config on WCF service 我试图将这两个参数添加到WCF服务上的web.config中

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

Can someone please look at my config and try to help me ? 有人可以看看我的配置并尝试帮助我吗?

WCF service code: 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
        }
}

and here is my wcf web.config file: 这是我的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>

(i've edited it by visual studio context menu on file web.config) (我已经通过web.config文件中的visual studio上下文菜单对其进行了编辑)

WCF service has been running by 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();  
            }
}
    }
}

and client has just references to web service and connect it by : 并且客户端仅引用了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);
            }

i konw that i have pasted a lot of code, but i have no idea what to do with my web.config file 我知道我已经粘贴了很多代码,但是我不知道该如何处理我的web.config文件

the data which is being sending is not big, it is less than 1 MB 正在发送的数据不大,小于1 MB

Did you just put this configuration in the web.config? 您是否只是将此配置放在web.config中?

Since you're hosting your WCF as a console application you have to make the configuration in the App.config of the hosting application. 由于将WCF托管为控制台应用程序,因此必须在托管应用程序的App.config中进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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