2017-12-13 8 views
1

現在、WCFサービスとC#基本Winformアプリケーションで再生しています。どちらも別のサーバーにあります。私は、C#アプリケーションがWCFを使用して他のサーバーからファイルを取得しようとしています。ここではWCFのコードだ:WCFがストリームを返すときにクライアントが終了しました

public Stream GetData(string fileName) 
{ 
    string filePath; 
    FileStream file = null; 
    try 
    { 
    // Stuff 

    file = File.OpenRead(Path.Combine(filePath, fileName)); 

    file.Position = 0L; 

    return (Stream)file; 

    } 
    catch (Exception ex) 
    { 
    // Trace stuff 
    return Stream.Null; 
    } 
} 

、これは動作契約です:

[OperationContract] 
Stream GetData(string fileName); 

これは、クライアントの設定ファイルです:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="NetTcpBindingEndpoint" transferMode="Streamed" closeTimeout ="10:00:00" openTimeout="10:00:00" sendTimeout="10:00:00" receiveTimeout ="10:00:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
      <security mode="None" /> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://SERVER/UpdaterUtilsWCF" binding="netTcpBinding" 
     bindingConfiguration="NetTcpBindingEndpoint" contract="UpdaterUtilsWCF.IUpdaterUtilsWCF" 
     name="NetTcpBindingEndpoint"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 

、これはWCFの設定ファイルです:

<system.serviceModel> 
    <bindings> 
    <netTcpBinding> 
    <binding name="TCPBinding_IDataService" openTimeout="10:00:00" 
       closeTimeout="10:00:00" 
       sendTimeout="10:00:00" 
       receiveTimeout="10:00:00" 
     maxBufferPoolSize="2147483647" 
       maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647" 
     transferMode="Streamed"> 
     <security mode="None" /> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <services> 
     <service name="UpdaterWCF.UpdaterUtilsWCF"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPBinding_IDataService" 
      name="NetTcpBindingEndpoint" contract="UpdaterWCF.IUpdaterUtilsWCF"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      name="MexTcpBindingEndpoint" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://SERVER/UpdaterUtilsWCF" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="2147483647" maxConcurrentSessions="200" /> 
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

最大同時呼び出し、インスタンス、およびセッションは、WCF構成ファイルで最大に設定されています。

これは、クライアント・アプリケーションのコードです:

using (Stream stream = WCFClient.GetData(textBox1.Text)) 
    { 
     // stuff 
    } 

私はアプリケーションを実行すると、それはクライアント側(またはWCF側)でクラッシュが、ストリームは、クライアントアプリケーションに渡されたとき。 WCFのコードをトレースし、呼び出しが行われ、WCFの最後に戻りコードが呼び出されます。 (400キロバイト)エラーはすぐにコールした後に表示され、ファイルが非常に小さいここでエラーです:

System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '10:00:00'. System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)

これで私を助けてください。

  • EDITED I'vが、これは通常の構成で問題となっている、私の経験では、両方のアプリを

答えて

0

多量のデバッグの後、私は問題を発見しました。

finally 
    { 
     if (file != null) 
     { 
     file.Close(); 
     file = null; 
     } 
    } 

クライアントがストリームを受信して​​いる間にストリームがWCF側に閉じた:キャッチ - 私のWCFサービスのコードでは、私は、try後のストリームressourceリリースを実装しました。私は私の質問(コンフィギュレーション・ファイルの一部)を編集した IOException on streamed file upload via WCF over HTTP

0

を全体system.modelを追加しました。開始するための良い例があることを確認してください。 Microsoftの例はここにあります: https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-enable-streaming が良いスタートです。 大きなファイルを送信する前に基本機能を確認するには、3つのバッファサイズをすべて設定するか、少数の文字でテストします。

<basicHttpBinding> 
    <binding name="HttpStreaming" maxBufferPoolSize="2147483647" 
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed"/> 

</basicHttpBinding> 
<!-- an example customBinding using Http and streaming--> 
<customBinding> 
    <binding name="Soap12"> 
    <textMessageEncoding messageVersion="Soap12WSAddressing10" /> 
    <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/> 
    </binding> 
</customBinding> 
+0

とバッファサイズのため、さらにはすべての同時バッファ値とクォータのためにすべての最大値を試してみました:

これは私が私の答えを見つけたところです。それでも同じエラーがあります。 – Alexandre

+0

@Alexandre、あなたがクライアントとサーバーの両方のsystem.serviceModelセクション全体を投稿した場合は、これについて少し気をつけてください。 –

関連する問題