2012-03-14 24 views
1

同様の質問が流れていて、私はすべてを見ていました。誰も私の問題を解決できないようです。WCFサービスによる大きなファイル

- UPDATE: -

私は、WCFサービスを使用してデータベースに文書(PDF、DOC、または何でも)をアップロードしようとしています。ここで

using (var cw = new WCFClientWrapper<ICommonService>()) 
{ 
    cw.Channel.DocumentInsert(content, filename, contentType); 
} 

契約の署名である:サービスへ 呼び出しは次のようになります

[OperationContract] 
void DocumentInsert(byte[] content, string fileName, string contentType); 

これが何であるかのように私は、コンテンツのためにバイト配列を渡していますのでご注意ください物事をDBに保管するために渡す必要があります。

- アップデートの終わり -

私は正常に小さなファイル(カップルキロバイト)をアップロードすることができます。私は大きな何か(20キロバイト)をアップロードしようとすると、しかし、私は例外を取得:「DocumentInsert」操作 のための要求メッセージの本文をデシリアライズでエラー: メッセージをデシリアライズしようとしているときにフォーマッタが例外をスローした

。最大配列長の制限(16384)は、XMLデータの読み取り中に を超えました。 XMLリーダーを作成するときに使用されるXmlDictionaryReaderQuotas オブジェクトのMaxArrayLengthプロパティを変更すると、この割り当てが増加する可能性があります( )。 1行目、31774.

エラーは明らかです... MaxArrayLengthを増やしてください。私はそれを成功させることなく成し遂げました。以下は私のweb.configsから関連する部分がある

クライアント:

<system.serviceModel> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="SecureBehavior"> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <bindings> 
     <basicHttpBinding> 
     <binding name="WSHttpBinding_Service" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="262144" messageEncoding="Text" 
      textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 

    <client> 
     <endpoint address="http://dev.svc.someurl.com/CommonService.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="WSHttpBinding_Service" 
       behaviorConfiguration="SecureBehavior" 
       contract="MyApp.Contracts.ServiceContracts.ICommonService" 
       name="MyApp.Contracts.ServiceContracts.ICommonService"> 
     </endpoint> 
    </client> 

    </system.serviceModel> 

サービス:

<system.serviceModel> 
    <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="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <bindings> 
     <basicHttpBinding> 
     <binding name="MyBasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 

    <services> 
     <service name="MyApp.WCFServices.CommonService"> 
     <endpoint address="" 
        binding="basicHttpBinding" 
        bindingConfiguration="MyBasicHttpBinding" 
        contract="MyApp.Contracts.ServiceContracts.ICommonService"> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" /> 
     </service> 
     <service name="MyApp.WCFServices.AccountService"> 
     <endpoint address="" 
        binding="basicHttpBinding" 
        bindingConfiguration="MyBasicHttpBinding" 
        contract="MyApp.Contracts.ServiceContracts.IAccountService"> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

取り付け診断が示しています

  • 構成サービス:エラー/警告なし
  • オープンサービス:警告 - 構成評価コンテキストが見つかりません - 一致するタグが見つかりませんでした。デフォルトのエンドポイントが追加されました。無 エラー/警告
  • 処理メッセージ1:エラーなし/警告
  • 処理アクション「
  • は 'http://dev.svc.someurl.com/CommonService.svc'に聞きますhttp://tempuri.org/ICommonService/DocumentInsert ' :私が最初に書いた例外をスローします。

何か助けていただければ幸いです。

答えて

0

私は数ヶ月前に同じ例外を見つけました。 WCFサービスとの間で大きなデータを送受信するには、transferMode="Streamed"を設定する必要があります。 TransfermodeをBufferedとして使用すると、実際にアップロード/ダウンロードする前にファイル全体がメモリに保存されます。したがって、WebクライアントとWCFサービスホストの両方で大きなバッファが必要になります。ストリーミング転送では、大きなメモリバッファが不要になり、サービスのスケーラビリティが向上します。 transfermodeの詳細については、MSDNの記事TransferMode Enumeration

+0

このご意見ありがとうございます。しかし、助けなかった。それは私のバインディングを無視し、デフォルトのものを使用するように見えます。私はなぜ、どのように – Dmitry

0

を参照してください。苦労の日の後、私はついに問題を発見しました。 私は念のWCFのweb.configファイル内のタグの名前は、名前空間とサービスの名前と一致することを確認する必要がありました:

<service name="ServicesImplementation.WcfServices.CommonService"> 

残念ながら、それは君たちがその情報に基づいて、見るであろうものではありませんでした私は提供した。

関連する問題