문제

이제 지난 2 시간 동안 400- Badrequest 코드를 조사했습니다. BindingConfiguration 속성이 올바르게 설정되도록하는 데 많은 수신이 있습니다.

자, 나는 내가있는 건물을 파괴하기 전에 당신의 도움이 필요합니다 :-)

WCF RESTFULL 서비스를 실행합니다 (이 리소스를 사용하여 영감을주기 위해 매우 가볍습니다. http://msdn.microsoft.com/en-us/magazine/dd315413.aspx) (현재) 포스트 동사를 통해 제공된 xmlelement (pox)를 수용합니다.

나는 현재 진정한 클라이언트를 구현하기 전에 Fiddler의 요청 빌더 만 사용하고 있습니다 (이것은 혼합 환경이므로).

65K보다 작은 XML의 경우이 작업을 수행하면 잘 작동합니다. 더 크게 작동합니다.이 예외는 발생합니다. 들어오는 메시지 (65536)의 최대 메시지 크기 할당량이 초과되었습니다. 할당량을 늘리려면 적절한 바인딩 요소에 MaxReceivedMessagesIZE 속성을 사용하십시오.

다음은 내 web.config 파일입니다 (클라이언트 태그를 포함하여 (절망적 인 시간!)) :

<system.web>
    <httpRuntime maxRequestLength="1500000" executionTimeout="180"/>
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxReceivedMessageSize="1500000" maxBufferPoolSize="1500000" maxBufferSize="1500000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="1500000" maxArrayLength="1500000" maxBytesPerRead="1500000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <client>
      <endpoint address="" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" contract="Commerce.ICatalogue"/>
    </client>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Catalogue">
        <endpoint address="" 
                  behaviorConfiguration="RestFull" 
                  binding="webHttpBinding"
                  bindingConfiguration="WebHttpBinding" 
                  contract="Commerce.ICatalogue" />
        <!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" / -->
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestFull">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

> 65k XML ;-)로 성공적인 전화로 이어지는 도움에 미리 감사드립니다.

도움이 되었습니까?

해결책

좋아, 이것은 정말로 저를 해결하는 데 어려움을 겪었습니다. 도전은 사실, 내가 <%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="fullyQualifiedClassName" %>, 이것은 멋지고 쉬운 공장 구현 접근법입니다.

그러나이 접근법에는 단점이 있습니다. Web.config 파일에는 구성이 필요하지 않기 때문에 WebServiceHostFactory Class By Design은 Web.config 파일에서 읽지 않습니다. 알아요; 이 클래스에서 상속받을 수 있고 적절한 변경을 할 수 있도록 구성 파일에서 실제로 읽을 수 있지만 이것은 약간의 범위가 아닌 것처럼 보였습니다.

저의 해결책은 WCF를 구현하는보다 전통적인 방법으로 돌아가는 것이 었습니다. <%@ ServiceHost Service="fullyQualifiedClassName" CodeBehind="~/App_Code/Catalogue.cs" %>, 그런 다음 Web.Config 파일에서 이미 구성된 값을 사용하십시오.

다음은 수정 된 web.config 파일입니다 (Maddox 두통과 관련하여) :

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="XmlMessageBinding" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="fullyQualifiedClassName" behaviorConfiguration="DevelopmentBehavior">
        <endpoint name="REST" address="" binding="webHttpBinding" contract="fullyQualifiedInterfaceName" behaviorConfiguration="RestEndpointBehavior" bindingConfiguration="XmlMessageBinding" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestEndpointBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DevelopmentBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
        <behavior name="ProductionBehavior">
          <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="false"/>
          <serviceMetadata httpGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

이 변경의 또 다른 이점은 이제 .NET에서 직접 WCF-Rest 서비스를 참조 할 수 있다는 것입니다. 이는 솔루션을 통해 공장 모델과 XMLELEMENT 구현을 사용하여 수행 할 수 없습니다.

나는 이것이 비슷한 문제를 가진 다른 사람들을 도울 수 있기를 바랍니다 ...

다른 팁

나는 이것이 아주 오래된 질문이라는 것을 알고 있으며 이미 대답이 있습니다 ...

그래도...

이 "문제"를 해결하기 위해 내가 한 일은 WebServiceHostFactory에서 상속 된 공장을 만들고 WebServiceHost에서 상속 된 사용자 정의 서비스 호스트를 만들었습니다.

그리고 호스트에서 나는 이와 같은 Onopening 방법을 무시했습니다.

protected override void OnOpening()
        {
            base.OnOpening();

            foreach (var endpoint in Description.Endpoints)
            {
                var binding = endpoint.Binding as System.ServiceModel.Channels.CustomBinding;

                foreach (var element in binding.Elements)
                {
                    var httpElement = element as System.ServiceModel.Channels.HttpTransportBindingElement;
                    if (httpElement != null)
                    {
                        httpElement.MaxBufferSize = 2147483647;
                        httpElement.MaxReceivedMessageSize = 2147483647;
                    }
                }
            }

        }

나는 같은 문제가 있다고 생각하지만 WebHTTP의 기본 결합을 구성했을 때 다음과 같이 작동했습니다.

<bindings>
        <webHttpBinding>
            <binding maxReceivedMessageSize="2000000"
                      maxBufferSize="2000000">
                <readerQuotas maxStringContentLength="2000000"/>
            </binding>
        </webHttpBinding>
    </bindings>

관찰 : 바인딩에 이름이 없습니다.

이것은 절대적으로 최소한의 WCF 서버 및 클라이언트 작품 으로이 문제를 재현하는 블로그 항목입니다.

WCF- 클라이언트 측 현악기 길이 예외 고정

특히 사용자 정의 바인딩 구성이 필요할 수 있습니다. 최소한이 샘플을 재현하면 특정 상황에 대한 아이디어가 줄 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top