5

C#でWCFを使用してクライアントからサーバーに大きなファイルを送信する方法は?構成コードの下。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="HttpStreaming_IStreamingSample" 
                         maxReceivedMessageSize="67108864"
                          transferMode="Streamed">
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint 
            address="http://localhost:4127/StreamingSample.svc"
            binding="basicHttpBinding" 
            bindingConfiguration="HttpStreaming_IStreamingSample"
            contract="StreamingSample.IStreamingSample" 
            name="HttpStreaming_IStreamingSample" />
    </client>
</system.serviceModel>
4

3 に答える 3

6

Dzmitry が既に指摘したように、ストリーミングを確認する必要があります。

大きなファイルをストリームとしてサービスに送信できるようにするには、次のことを行う必要があります。

  • Stream入力パラメーターとしてa を受け入れるサービス メソッドを作成する
  • を使用するバインディング構成を (サーバーとクライアントの両方で) 作成します。transferMode=StreamedRequest
  • クライアントでストリームを作成し、それをサービス メソッドに送信します

まず、サービス コントラクトにメソッドが必要です。

[ServiceContract]
interface IYourFileService
{
   [OperationContract]
   void UploadFile(Stream file)
}

次に、バインディング構成が必要です。

<bindings>
  <basicHttpBinding>
    <binding name="FileUploadConfig"
             transferMode="StreamedRequest" />
  </basicHttpBinding>
</bindings>

およびそのバインディング構成を使用するサービスのサービス エンドポイント:

<services>
  <service name="FileUploadService">
     <endpoint name="UploadEndpoint"
               address="......."
               binding="basicHttpBinding"
               bindingConfiguration="FileUploadConfig"
               contract="IYourFileService" />
  </service>
</services>

次に、クライアントで、たとえばファイルストリームを開き、それを閉じずにサービスメソッドに送信する必要があります。

それが役立つことを願っています!

マルク

于 2009-10-05T11:57:49.317 に答える
2

WCFストリーミング機能を確認できます。

于 2009-10-05T11:26:03.343 に答える
2

(上記の) readerQuota 設定を増やすことに加えて、httpRuntime 属性内の maxRequestLength も増やす必要がありました。

<system.web>
    <httpRuntime maxRequestLength="2097151" />
</system.web>
于 2011-01-04T19:37:23.360 に答える