質問
画像のサイズを変更する小さなWCF / WPFアプリを作成していますが、クライアントからサービスにサイズ28Kの画像を送信しようとすると、WCFが悲しみを与えます。より小さな画像を送信すると、サービスは正常に動作します。これは構成の問題であるとすぐに判断し、バインド構成のMaxArrayLengthプロパティに関する投稿を見てWebを探しました。クライアントとサーバーの両方のこれらの設定の制限を最大2147483647に引き上げましたが、それでも次のエラーが表示されます。
メッセージをデシリアライズしようとしてフォーマッターが例外をスローしました:デシリアライズしようとしてエラーが発生しました パラメーター http://mywebsite.com/services/servicecontracts/2009/01:OriginalImage。 InnerExceptionメッセージは、「System.Drawing.Image型のオブジェクトの逆シリアル化中にエラーが発生しました。 XMLデータの読み取り中に、配列の最大長クォータ(16384)を超えました。 XMLリーダーの作成時に使用されるXmlDictionaryReaderQuotasオブジェクトのMaxArrayLengthプロパティを変更することにより、このクォータを増やすことができます。詳細については、InnerExceptionを参照してください。
クライアントとサーバーの設定を同じにしましたが、次のようになります。 サーバー:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:900/mex/"/>
<add baseAddress="net.tcp://localhost:9000/" />
</baseAddresses>
</host>
<endpoint binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
そして私のクライアント設定は次のようになります:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:9000/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_ImageResizerServiceContract"
contract="ImageResizerService.ImageResizerServiceContract"
name="NetTcpBinding_ImageResizerServiceContract">
<identity>
<userPrincipalName value="me@domain.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
これらの値を何に設定しても、wcfが16384を超えているためにファイルをシリアル化できないというエラーが表示されます。アイデアはありますか?
更新: userPrincipalNameタグのメールアドレスがプライバシー保護のために変更されました
解決
My Bad-サーバー側の設定で、バインド設定をエンドポイントに適用するのを忘れました。サーバー構成は次のようになります。
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:900/mex/"/>
<add baseAddress="net.tcp://localhost:9000/" />
</baseAddresses>
</host>
<endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
bindingConfiguration = <!> quot; NetTcpBinding_ImageResizerServiceContract <!> quot;に注意してください。 netTcpエンドポイントに追加されました。私のアプリはより大きな画像で動作するようになりました。甘い。
他のヒント
バインディングに<readerQuotas>
を追加してください。
これは、byte []のアップロードおよびダウンロード中の主な問題であり、私の問題を解決しました。
<basicHttpBinding>
<binding name="ServicesBinding" transferMode="Streamed" maxBufferSize="200000000"
maxReceivedMessageSize="200000000" messageEncoding="Text"
receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
Microsoft SDK SvcConfigEditorを使用しました。 Visual Studio(独自のバージョンがある)を使用している場合、これがあります。また、無料でダウンロードできます。
ハードドライブ上(Program FilesとProgram Files(x86)の両方を確認してください):
C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Bin \ NETFX 4.0 Tools \ SvcConfigEditor.exe
C:\ Program Files \ Microsoft SDKs \ Windows \ v7.1 \ Bin \ NETFX 4.0 Tools \ SvcConfigEditor.exe
Microsoft SDKが複数インストールされている場合、使用するバージョンは、開発中の.NETのバージョンによって異なります。このツールは、間違ったバージョンで.dllファイルを開こうとしたことを知らせるエラーをスローします。
ツールを使用するには、サービス<!>#8217; sの.dllファイルをポイントし、ツールに負荷をかけさせます。これは、サービスと通信するサービス(プロキシサービス)がある場合に特に役立ちます。また、<!>#8217;おそらく、クライアント(アプリケーション)とサーバー構成(Webサービス)の両方の構成設定が必要になることに注意してください。
サーバー側のエンドポイントの設定がありませんでした。私は2つのことをしなければなりませんでした:
- SvcConfigEditorを使用して構成されたサーバー側の構成にエンドポイントを配置
- SvcConfigEditorツールでMaxArrayLengthを設定することを忘れないでください
また、ASP.NETはこの値を気にしているため、構成のバインドを単純化して無効にすることをお勧めします。
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
それは機能しています。以前はwcfサービスを参照するときにnet.tcp://myservice.com/Ac_Service.svc/mexの参照を表示していましたが、現在は http://myservice.com/Ac_Service.svc?wsdl
今後も問題なく動作します。