質問

現在、過去2時間の400-BadRequestコードを調査しました。 多くのサジェスチョンは、bindingConfiguration属性が正しく設定されていることを確認することに向けられています。私の場合はそうです。

今、私がいる建物を破壊する前にあなたの助けが必要です:-)

WCF RestFullサービスを実行します(非常に軽量、インスピレーションにこのリソースを使用: http://msdn.microsoft.com/en-us/magazine/dd315413.aspx )これは(今のところ)POST動詞を通じて提供されるXmlElement(POX)を受け入れます。

現在、真のクライアントを実装する前にFiddlerのリクエストビルダーのみを使用しています(これは混合環境であるため)。

65Kより小さいXMLに対してこれを行うと、正常に動作します-大きくすると、この例外がスローされます。 着信メッセージの最大メッセージサイズクォータ(65536)を超えました。クォータを増やすには、適切なバインディング要素でMaxReceivedMessageSizeプロパティを使用します。

これは私のweb.configファイルです(これは(絶望的な時間!)のclient-tagを含めました):

<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>

<!> gt; 65K XMLでの成功した呼び出しにつながる助けを事前に感謝します;-)

役に立ちましたか?

解決

大丈夫、これは本当に解決に苦労しました。 課題は、私が<%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="fullyQualifiedClassName" %>を使用したことでした。これは、素晴らしく簡単なファクトリ実装アプローチです。

ただし、このアプローチには欠点があります。 web.configファイルでは構成が必要ないため、WebServiceHostFactoryクラスは設計上、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>

この変更のもう1つの利点は、.NETからWCF-restサービスを直接参照できることです。 Factoryモデルとソリューション全体でのXmlElementの実装を使用してこれを行うことはできません。

これが同様の問題を抱えている他の人の助けになることを願っています...

他のヒント

これは非常に古い質問であり、すでに回答があります...

とにかく...

この<!> quot; issue <!> quot;を解決するためにしたこと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