2015-06-16 3 views
0

Я пишу элемент управления загрузкой, который работает с сервисом WCF, и когда я пытаюсь загрузить файлы более 1 МБ. m получение этой ошибки:Невозможно записать данные в транспортное соединение: установленное соединение было прервано программным обеспечением вашего хост-компьютера

{System.IO.IOException: Unable to write data to the transport connection: 
An established connection was aborted by the software in your host machine. 
---> System.Net.Sockets.SocketException: An established connection was aborted by the 
    software in your host machine 
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
--- End of inner exception stack trace --- 
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) 
at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) 
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)} 

Я не знаю, связано ли это с параметром длины json max или нет. Я знаю, что в веб-приложений, которые я могу добавить это в файле web.config

<system.web.extensions> 
<scripting> 
    <webServices> 
    <jsonSerialization maxJsonLength="50000000"/> 
    </webServices> 
</scripting> 

Но я новичок в WCF и не имеют ни малейшего представления о том, как справиться с этим здесь ...

+0

Пожалуйста см. [«Если вопросы включают« теги »в их названиях?») (http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), где консенсус " нет, они не должны "! –

ответ

0

Я решил.

  1. удалить [WebInvoke...] и оставить только [OperationContract] в интерфейсе
  2. Используйте эти файлы конфигурации

клиента конфигурации:

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime maxRequestLength="2147483647" /> 
    </system.web> 

    <system.serviceModel> 
    <bindings> 
     <webHttpBinding> 

     <binding name="WebHttpBinding_IAttachmentService" closeTimeout="10:00:00" openTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00" 
       maxBufferSize="2147483647" 
       maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 

      <readerQuotas maxDepth="2147483647" 
         maxArrayLength="2147483647" 
         maxBytesPerRead="2147483647" 
         maxNameTableCharCount="2147483647" 
         maxStringContentLength="2147483647"/> 

      <security mode="None" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:54893/AttachmentService.svc" 
       binding="webHttpBinding" 
       bindingConfiguration="WebHttpBinding_IAttachmentService" 
       behaviorConfiguration="webHttpBehavior" 
       contract="XXX.Interfaces.IAttachmentService" /> 
    </client> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="webHttpBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <security> 
     <requestFiltering> 
     <requestLimits maxAllowedContentLength="1073741824" /> 
     </requestFiltering> 
    </security> 
    </system.webServer> 

Служба конфигурации:

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime maxRequestLength="2147483647" executionTimeout="3600" /> 
    </system.web> 

    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="XXX.Implementation.AttachmentService"> 
     <endpoint binding="webHttpBinding" 
        behaviorConfiguration="webHttpBehavior" 
        bindingConfiguration="higherMessageSize" 
        contract="XXX.Interfaces.IAttachmentService" /> 
     </service> 
    </services> 
    <bindings> 
     <webHttpBinding> 
     <binding name="higherMessageSize" transferMode="Streamed" closeTimeout="10:00:00" openTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00" 
       maxBufferSize="2147483647" 
       maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 

      <readerQuotas maxDepth="2147483647" 
         maxArrayLength="2147483647" 
         maxBytesPerRead="2147483647" 
         maxNameTableCharCount="2147483647" 
         maxStringContentLength="2147483647"/> 

      <security mode="None"/> 
     </binding> 
     </webHttpBinding> 
    </bindings> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="webHttpBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule"/> 
    </modules> 
     <handlers> 
        <remove name ="WebDAV"/> 
    </handlers> 
    <security> 
     <requestFiltering> 
     <requestLimits maxAllowedContentLength="2147483647" /> 
     </requestFiltering> 
    </security> 
    </system.webServer> 
0

Возможно, вы нажмете время ожидания. Прежде всего, включите keepalive в свою привязку. Во-вторых, отметьте отметки времени в запросе и ответе. Если между отправителем и получателем есть межсетевой экран, убедитесь, что он не закрывает соединение из-за таймаута в режиме ожидания.

+0

По умолчанию значение keepAlive истинно, и я не думаю, что он имеет какое-то время делать таймаут здесь, потому что исключение сразу же выбрано. –

Смежные вопросы

 Смежные вопросы