Problem DownLoad File

The scenario is:

A Host Service communicate directly with a client without ServiceSite in IIS.

I want to download a file from Server to a Client. If the size file is more than 60kb the host service generate this error:

{System.ServiceModel.CommunicationException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: Connessione in corso interrotta forzatamente dall'host remoto. ---> System.Net.Sockets.SocketException: Connessione in corso interrotta forzatamente dall'host remoto
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebRequest request, WebException webException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ServiceLibrary.IEchoService.DownloadFile(String fileName)
at Client.Program.Main(String[] args) in C:\Temp\Winfx\WCF\EchoServiceClient\Program.cs:line 41}

Service Library

[ServiceContract(Namespace="")]

public interface IEchoService{

[OperationContract]

Byte[] DownloadFile(String fileName);}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,ConcurrencyMode=ConcurrencyMode.Multiple)]

public class EchoService : IEchoService

{public Byte[] DownloadFile(String fileName)

{byte[] cic = File.ReadAllBytes(fileName);return cic;}}

CLIENT APP.Config

< xml version="1.0" encoding="utf-8" >

<configuration>

<system.serviceModel>

<client>

<endpoint name="httpEndpoint"

address="http://localhost:8080/echo/svc"

binding="basicHttpBinding"

bindingConfiguration="ServiceBinding"

contract="ServiceLibrary.IEchoService"/>

</client>

<bindings>

<basicHttpBinding>

<binding name="ServiceBinding" closeTimeout="01:00:00" openTimeout="01:00:00" sendTimeout="01:00:00" receiveTimeout="01:00:00">

<security mode="None" />

</binding>

</basicHttpBinding>

</bindings>

</system.serviceModel>

</configuration>

I need some help.

Bye

Laura



Answer this question

Problem DownLoad File

  • flloydwaters

    the error is "Insufficient resources of system in order to complete the demanded service ". it could be the firewall

    Thanks

    Laura


  • Erik Steiner

    Hi.

    You may need to set your maxMessageSize.

    <bindings>
      <basicHttpBinding>
       <binding name="Binding1" 
            hostNameComparisonMode="StrongWildcard" 
            receiveTimeout="00:10:00"
            sendTimeout="00:10:00"
            openTimeout="00:10:00"
            closeTimeout="00:10:00"
            maxMessageSize="65536" 
            maxBufferSize="65536" 
            maxBufferPoolSize="524288" 
            transferMode="Buffered" 
            messageEncoding="Text" 
            textEncoding="utf-8"
            bypassProxyOnLocal="false"
            useDefaultWebProxy="true" >
         <security mode="None" />
       </binding>
      </basicHttpBinding>
    </bindings>
    

    Also, please see this article moving large amounts of data:

    http://blogs.msdn.com/yassers/archive/2006/01/21/515887.aspx

    Thanks!

    Scott



  • Geoff GB

    Hi,

    I resolved the problem to insert the attribute "transferMode="Streamed" " in client config file.

    <basicHttpBinding>
    <binding name="ServiceBinding" transferMode="Streamed" closeTimeout="01:00:00" openTimeout="01:00:00"
    receiveTimeout="01:00:00" sendTimeout="01:00:00" maxReceivedMessageSize="2147483647" />
    </basicHttpBinding>


  • momibutt

    //I changed your config file

    changes:

    //increased Max Received Message size

    maxReceivedMessageSize="2147483647"

    //Adding tracing info to trouble shoot this problem,by default,This will create trace in c:\,if you want change the path,you can change,once you have trace info,open this trace in svctraceviewer(http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=373460&SiteID=1)

    can you please try this config,if you still see the problem,can you please send me trace files and if possible repro code also,my email id is madhup@microsoft.com

    CLIENT CONFIG FILE:

    < xml version="1.0" encoding="utf-8" >

    <configuration>

    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing"
                propagateActivity="true">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="ServiceModel Listener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
            <source name="System.ServiceModel.Channels.MessageLogging" switchValue="Verbose, ActivityTracing">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="MessageLogging Listener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add initializeData="C:\client_tracelog.e2e" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="ServiceModel Listener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
                <filter type="" />
            </add>
            <add initializeData="C:\client_messages.e2e" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="MessageLogging Listener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
                <filter type="" />
            </add>
        </sharedListeners>
    </system.diagnostics>
    <system.serviceModel>

    <diagnostics>
        <messageLogging logEntireMessage="true" logMalformedMessages="true"
            logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
            maxMessagesToLog="10000" />
    </diagnostics>
    <client>
        <endpoint address="
    http://localhost:8080/echo/svc" binding="basicHttpBinding"
            bindingConfiguration="ServiceBinding" contract="ServiceLibrary.IEchoService"
            name="httpEndpoint" />
    </client>

    <bindings>
        <basicHttpBinding>
            <binding name="ServiceBinding" closeTimeout="01:00:00" openTimeout="01:00:00"
                receiveTimeout="01:00:00" sendTimeout="01:00:00" maxReceivedMessageSize="2147483647" />
        </basicHttpBinding>
    </bindings>

    </system.serviceModel>

    </configuration>

     



  • Rufus Littlefield

    Hi Laura,

    How big is this file ,If possible,can you please send me your repro code and file you are using for test,my email id is madhup@microsoft.com

    -Thank you

    Madhu



  • Problem DownLoad File