programing

원격 서버에서 예기치 않은 응답을 반환했습니다. (413) Request Entity Too Large.

muds 2023. 5. 26. 22:49
반응형

원격 서버에서 예기치 않은 응답을 반환했습니다. (413) Request Entity Too Large.

저는 FW4.0을 사용하여 WCF 애플리케이션 서비스를 구축하려고 합니다.서버와 클라이언트 간에 EntiryFramework 개체를 전송할 때 내 서비스가 올바르게 작동합니다.하지만 클라이언트에서 서버로 EF 개체를 전달하는 데 문제가 있습니다.

환경에 대한 자세한 내용은 다음과 같습니다. - 서비스가 IIS에서 로컬로 디버그 모드로 실행되고 있습니다. - Windows 7에서 이 모든 것을 실행하고 있습니다. - FW4.0에서 Visual Studio 2010을 사용하고 있습니다.

레코드를 저장하기 위해 서버에 개체(tblClient)를 보내려고 하는데 A가 계속해서 (413) Request Entity Too Large 오류가 발생합니다.전체 스택:

System.ServiceModel.ProtocolException occurred
      HResult=-2146233087
      Message=The remote server returned an unexpected response: (413) Request Entity Too Large.
      Source=mscorlib
      StackTrace:
        Server stack trace:
           at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
           at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]:
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at ClientApp.ServiceReference1.IService.SaveClient(tblClient client)
           at ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient client) in C:\dufh\WPF Project\ClientApp\Service References\ServiceReference1\Reference.vb:line 2383
           at ClientApp.ViewModel.ClientViewModel.SaveClient() in C:\dufh\WPF Project\ClientApp\ViewModel\ClientViewModel.vb:line 48
      InnerException: System.Net.WebException
           HResult=-2146233079
           Message=The remote server returned an error: (413) Request Entity Too Large.
           Source=System
           StackTrace:
                at System.Net.HttpWebRequest.GetResponse()
                at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException:

저는 몇 가지 조사를 해 보았는데, 모두 maxBufferSize 및/또는 maxBufferPoolSize 및/또는 maxReceivedMessageSize 스위치가 클라이언트 구성 앱에서 충분히 크지 않다는 것을 지적합니다.구성. 그래서 maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"의 최대값으로 삽입했지만 오류는 여전히 남아 있습니다.

전체 클라이언트 앱입니다.구성

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MVVM Sampling"/>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:7803/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
          name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

그리고 전체 웹.WCF 서비스 웹을 구성합니다.구성

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

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <connectionStrings>
    <add name="MaitreEntities" connectionString="metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=INFOFILE2\SQL2008R2;initial catalog=0001ConneryFerland;user id=sa;password=kermit80;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>


Any help would be very welcome :-)

기록을 위해.

난 이해한 것 같아.웹.서비스의 구성에 바인딩 정보가 없습니다.내가 이 정보를 넣었고, voila!

<bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
</bindings>

여기서는 바인딩에 이름이 지정되지 않았습니다.

서비스에 대한 명시적 끝점(구성 파일에 정의된 끝점을 의미)이 없으므로 선언한 바인딩 구성("BasicHttpBinding_)ISservice")가 사용되고 있지 않습니다.WCF는 기본 바인딩과 함께 기본 끝점을 제공합니다.basicHttpBinding당신이 그것을 과도하게 하지 않는 한.protocolMapping구성 파일의 섹션)을 참조하십시오.

서비스의 구성 파일에서 이 문제를 해결하는 방법은 두 가지가 있습니다.

"BasicHttpBinding_"을 만들 수 있습니다.IService"를 제거하여 기본 구성name속성:

<binding maxBufferPoolSize="2147483647".....

또는 구성에서 엔드포인트를 명시적으로 정의하고 바인딩 구성을bindingConfiguration엔드포인트의 속성입니다.

<services>
    <endpoint address="" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService"     
              contract="ServiceReference1.IService"  />
</services>

사용자 정의 바인딩을 생성하는 경우(예:나의 기본 바인딩,

  <basicHttpBinding>
      <binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
               maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
            <readerQuotas maxDepth="32" maxBytesPerRead="200000000" 
             maxArrayLength="200000000" maxStringContentLength="200000000" />
      </binding>
  </basicHttpBinding>

413 오류를 방지하려면 서비스 끝점에 대해 바인딩 구성="MybasicBinding"지정해야 합니다.

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MybasicBinding" contract="WCFService.IService" />

이 문제를 해결하고 web.config 파일을 더 잘 볼 수 있는 또 다른 방법은 "Microsoft 서비스 구성 편집기"(C:\Program Files(x86)\Microsoft SDKs\Windows\v8)로 web.config 파일을 편집하는 것입니다.1A\bin\NETFX 4.5.1 Tools\SvcConfigEditor.exe)

바인딩이 지정되지 않고 httpsgetenabled가 true이면 서비스 응용 프로그램의 web.config에서 기본적인 httpsbinding을 설정해야 할 수 있습니다.

<bindings>
  <basicHttpsBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpsBinding>

저는 이 오류를 받고 있었습니다.바인딩 구성을 만들었지만 엔드포인트를 해당 구성으로 설정하지 못했습니다.따라서 엔드포인트가 기본 설정으로 명명되지 않은 바인딩 구성을 사용하고 있었습니다.maxReceivedMessageSize는 65k였습니다.

IIS 제한 때문일 수도 있습니다.IIS 관리자-> 응용 프로그램 선택-> 기능 뷰-> 요청 필터링-> 기능 설정 편집-> 허용되는 최대 콘텐츠 길이 30000000(28).6M)-> 가치 상승

언급URL : https://stackoverflow.com/questions/20575946/the-remote-server-returned-an-unexpected-response-413-request-entity-too-larg

반응형