2017-12-13 1 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 서비스 코드에서 나는 시도 후 스트림 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 이 좋은 시작일 수 있습니다. 큰 파일을 보내기 전에 기본 기능을 확인하려면 세 가지 버퍼 크기를 모두 설정하거나 몇 자만의 파일로 테스트하십시오.

<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 섹션 전체를 게시한다면, 이것에 대해 밝혀 줄 수도 있습니다. –

관련 문제