locked
How to send large amount of data via WCF Service RRS feed

  • Question

  • Hi,

    I am working an application which is a Silverlight application that uses WCF. When I send small amount of data everything is working fine. But when I send large amount of data like 23454 records, I am getting error message.

    Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.


    An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/SAMWCFService/Service1/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

    Server stack trace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.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.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 ISAMService.GetGOMBlocksForAState(String stateID)
       at SAMServiceClient.GetGOMBlocksForAState(String stateID)

    Inner Exception:
    The underlying connection was closed: An unexpected error occurred on a receive.
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

    Inner Exception:
    Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
       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)

    Inner Exception:
    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.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)


    App.config of my WCF service

    <?xml version="1.0"?>
    <configuration>

      <system.web>
        <compilation debug="true"/>
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="default" maxReceivedMessageSize="73400320"  maxBufferPoolSize="73400320"
                     closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" >
              <readerQuotas  maxArrayLength="73400320" maxBytesPerRead="73400320" maxNameTableCharCount="73400320"
                             maxDepth="73400320" maxStringContentLength="73400320" />
            </binding>
          </wsHttpBinding>
        </bindings>

        <!--<bindings />-->
        <client />
        <services>
          <service name="SAMWCFService.SAMService">
            <endpoint address="" binding="wsHttpBinding" contract="SAMWCFService.ISAMService">
              <!--<endpoint address="" binding="basicHttpBinding" contract="SAMWCFService.ISAMService">-->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8732/Design_Time_Addresses/SAMWCFService/Service1/"/>
                <!--<add baseAddress="http://hacsstctapp07.ihess.com/samwcfservices/Service1"/>-->
                <!--<add baseAddress="http://sam.ihess.com/service1.svc"/>-->
              </baseAddresses>
            </host>
          </service>
        </services>
        <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>
      </system.serviceModel>

    <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>


    Web.config for my WCF service host

    <?xml version="1.0"?>
    <configuration>
        <configSections>
      <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
       <section name="SAMWCFServiceHost.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </sectionGroup>
     </configSections>
     <system.web>
       <httpRuntime maxRequestLength="73400" />
        <identity impersonate="false"/>
        <authentication mode="Windows"/>
        <authorization>
          <deny users="?"/>
        </authorization>
            <compilation debug="true" targetFramework="4.0">
            </compilation>
            <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
        <system.serviceModel>
            <bindings>
       <customBinding>
        <binding name="SAMWCFServiceHost.ADIUserInfoWCFService.customBinding0">
         <binaryMessageEncoding />
         <httpTransport />
        </binding>
       </customBinding>
      </bindings>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
       multipleSiteBindingsEnabled="true" />
      <services>
       <service name="SAMWCFServiceHost.ADIUserInfoWCFService">
        <endpoint address="" binding="customBinding" bindingConfiguration="SAMWCFServiceHost.ADIUserInfoWCFService.customBinding0"
         contract="SAMWCFServiceHost.ADIUserInfoWCFService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
      </services>
      <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>
            <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
        </system.serviceModel>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true">
            </modules>
        </system.webServer>
     <applicationSettings>
      <SAMWCFServiceHost.Properties.Settings>
       <setting name="SAMWCFServiceHost_ws_UserInfo_UserInfo" serializeAs="String">
        <value>http://hesswebservices.ihess.com/adlib/userinfo.asmx</value>
       </setting>
      </SAMWCFServiceHost.Properties.Settings>
     </applicationSettings>
    </configuration>


    ServiceReferences.ClientConfig of my Silverlight Client application is

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ISAMService"  maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                      
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
              <!--<wsHttpBinding>
                <binding name="BasicHttpBinding_ISAMService" maxReceivedMessageSize="2147483647"  maxBufferPoolSize="2147483647">
                  <readerQuotas  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"
                                 maxDepth="2147483647" maxStringContentLength="2147483647" />
                  <security mode="None" />
                </binding>
              </wsHttpBinding>-->
              <!--<wsHttpBinding>
                <binding name="default" maxReceivedMessageSize="2147483647"  maxBufferPoolSize="2147483647" >
                  <readerQuotas  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"
                                 maxDepth="2147483647" maxStringContentLength="2147483647" />
                </binding>
              </wsHttpBinding>-->
                <customBinding>
                    <binding name="CustomBinding_ADIUserInfoWCFService">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:1462/Service1.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_ISAMService" contract="SAMWCFServiceReference.ISAMService"
                    name="BasicHttpBinding_ISAMService" />
                <endpoint address="http://localhost:1462/ADIUserInfoWCFService.svc"
                    binding="customBinding" bindingConfiguration="CustomBinding_ADIUserInfoWCFService"
                    contract="ADIUserInfoWCFService.ADIUserInfoWCFService" name="CustomBinding_ADIUserInfoWCFService" />
            </client>
        </system.serviceModel>
    </configuration>


    It is urgent for me. I have tried all ways I found online


    Monday, November 22, 2010 10:46 AM

Answers

  • In your local machine you may ne using app.config but when you deploy it on the server, app.config file should be renamed as <wcfproject/dll name>.config

    I had similar issue where I had deployed the file with name app.config which was working fine on my local but not when deployed on the server, Hope that helps.

    Monday, November 22, 2010 5:43 PM

All replies

  • Try add <ReaderQuotas ... />  to your <customBinding name="SAMWCFServiceHost.ADIUserInfoWCFService.customBinding0" .../>

    Monday, November 22, 2010 11:00 AM
  • Hi,
    try this configuration data:


    <configuration>
        <system.web>
            <compilation debug="true" targetFramework="4.0" />
            <httpRuntime maxRequestLength="40000"/>
        </system.web>
    
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="BehaviorCfg">
                      <serviceMetadata httpGetEnabled="true" />
                      <serviceDebug includeExceptionDetailInFaults="true" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <bindings>
              <basicHttpBinding>
                  <binding  maxReceivedMessageSize="2147483647">
                      <readerQuotas
                        maxDepth="64"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="4096"
                        maxNameTableCharCount="16384"/>
                  </binding>
              </basicHttpBinding>
            </bindings>
            <services>
                <service name="YourService" behaviorConfiguration="BehaviorCfg">
                    <endpoint address="" contract="sl1.Web.YourServiceContact" binding="basicHttpBinding" />
                </service>
            </services>
            <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        </system.serviceModel>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true"/>
        </system.webServer>
    </configuration>


    Monday, November 22, 2010 11:01 AM
  • To Andris,


    I have added the following as per your advice. I have added this in Web.config of my host

    <bindings>
       <customBinding>
        <binding name="SAMWCFServiceHost.ADIUserInfoWCFService.customBinding0">
          <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
            <readerQuotas maxArrayLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647"/>
          </binaryMessageEncoding>
         <httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          maxBufferSize="2147483647" />
        </binding>
       </customBinding>


    Actually my project is this

    I have one WCF Class library project which will send data.


    One WCF host project and this will host my above project and also one silverlight enabled wcf service named ADIUserInfoWCFService.


    Then Silverlight Client which is Silverlight application.

    Monday, November 22, 2010 12:45 PM
  • T MF,

    I have given the following config for my WCF Class library project App.config file


    <?xml version="1.0"?>
    <configuration>

      <system.web>
        <compilation debug="true"/>
        <httpRuntime maxRequestLength="2147483647"/>
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="default" maxReceivedMessageSize="2147483647"  maxBufferPoolSize="2147483647"
                     closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" >
              <readerQuotas  maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"
                             maxDepth="64" maxStringContentLength="2147483647" />
            </binding>
            
          </wsHttpBinding>
        </bindings>

        <!--<bindings />-->
        <client />
        <services>
          <service name="SAMWCFService.SAMService">
            <endpoint address="" binding="wsHttpBinding" contract="SAMWCFService.ISAMService" behaviorConfiguration="myLargeDataBehavior">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" behaviorConfiguration="myLargeDataBehavior"/>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8732/Design_Time_Addresses/SAMWCFService/Service1/"/>
              </baseAddresses>
            </host>
          </service>
        </services>
        
        <behaviors>
          <endpointBehaviors>
            <behavior name="myLargeDataBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </endpointBehaviors>
          <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" />
              
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>


    Actually my project is this


    1) One wcf class library. This send data. This has app.config


    2) one WCF service host application. This host above porject and in addition this has other Silverlight enabled WCF service which is ADIUserInfoWCFService.


    3) I have one Silverlight application which is client. This will have ServiceReferences.config file.


    I am also using WCF Test client but then also it is not working. It is really urgent.

    Monday, November 22, 2010 12:54 PM
  • If you want to do it using code then below id the code:

    using System.ServiceModel;


    Private ListsSoapClient _listWS;

    BasicHttpBinding binding = new BasicHttpBinding();
    EndpointAddress endpoint = new EndpointAddress(endpointUri);
    binding.MaxReceivedMessageSize = 2147483647;
    binding.MaxBufferSize = 2147483647;
    _listWS = new ListsSoapClient(binding, endpoint);
     _listWS.GetListItemsCompleted += new EventHandler<GetListItemsCompletedEventArgs>(_listWS_GetListItemsCompleted);


    _listWS.Get... Asy()

     

     
    Monday, November 22, 2010 1:49 PM
  • Hi Roshan,


    I am using config files. App.config for my wcf service...web.config for my wcf service host and servicesreferences.clientconfig on my client.. i need to use them

    Monday, November 22, 2010 2:31 PM
  • In your local machine you may ne using app.config but when you deploy it on the server, app.config file should be renamed as <wcfproject/dll name>.config

    I had similar issue where I had deployed the file with name app.config which was working fine on my local but not when deployed on the server, Hope that helps.

    Monday, November 22, 2010 5:43 PM