質問
私はファイルをアップロードするためのWCFサービスを作成していますが、Byte配列に16384を超える要素がある場合に例外をスローします。
これは例外の詳細です:
フォーマッタは、メッセージを脱必要にしようとしながら例外を投げました:操作「createdocument」のリクエストメッセージの脱気体化のエラー。 XMLデータの読み取り中に、最大配列長クォータ(16384)を超えています。このクォータは、XMLリーダーを作成するときに使用されるXMLDictionaryReaderQuotasオブジェクトのMaxArrayLengthプロパティを変更することで増加する場合があります。 1行目、位置22862。
クライアントとサーバーの両方の構成は、最大配列長クォータを2147483647に設定します。
クライアント構成:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDocumentLibraryService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50764/DocumentLibraryService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"
contract="DocumentLibrary.IDocumentLibraryService" name="BasicHttpBinding_IDocumentLibraryService" />
</client>
サーバー構成:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDocumentLibraryService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="BasicHttpBinding_IDocumentLibraryService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" />
<endpoint binding="basicHttpBinding" name="DocumentLibraryService" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" address=""
bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"/>
</service>
</services>
解決
私がする必要があるのは、web.configファイルのサービス名を名前空間でフルサービス名に変更することだけでした。
<service name="SampleNameSpace.DocumentLibraryService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" />
<endpoint binding="basicHttpBinding" name="DocumentLibraryService" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" address=""
bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"/>
</service>
他のヒント
構成は大丈夫だと思われるため、これは実際には答えではありません。コードのこれらの値を確認するだけで(出力してトレースまたはデバッグ)、 サービスホスト そしてその プロキシー 構成内の同じ値がチャネルにロードされていることを確認します。
可能性については、別のしきい値に到達し、エラーが誤解を招くということです
今私は ファイルをアップロードするためにBYTEアレイを使用することを強くお勧めします 特にXMLを使用する場合。これらはXMLアレイとして表され、構造は非常に肥大化したXMLになり、元のファイルの10倍かかります。
私は使うだろう:
- WCFストリーミング 基本的なバインディングでも機能します 超早い
- または、バイト配列を表します base64 ストリング。これには33%多くのスペースが必要ですが、1000%ではありません
アップデート
サービスの構成に使用されたバインディング名をトレースできます(WCF操作のいずれか内で使用します):
public int MyServiceOperation()
{
Trace.WriteLine(OperationContext.Current.EndpointDispatcher.ChannelDispatcher.BindingName)
....