将文件发送到 WCF 服务,套接字连接中止

Sending file to WCF service, socket connection aborted

我有一个 WCF 服务(服务器),其方法的签名是

public void SetProfilePic(String pSession, Applicant pApplicant)

申请人有 属性:

public byte[] Photo { get; set; }

我从客户端获取图像并调用 SetProfilePic。当图像较小时,大约 1cm X 1cm,效果很好,但是当图像较大时,大约 4cm X 3cm,出现以下错误

"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 '01:49:59.9779945'."

我已经增加了 app.config 文件中的 最大限制 ,但是我仍然遇到同样的错误。我在 buffered 模式下使用 NetTCPBinding。我也尝试过 MTOM。客户端和服务目前 运行 在同一台机器上,因为该项目仍处于初始开发阶段。

我在服务器端和客户端都启用了消息记录和跟踪,但是日志中没有提供更多详细信息,这不是很有帮助。

请在下面找到客户端和服务器的 App.config 文件。

我使用 WCF 的经验只有几个月。任何帮助表示赞赏。提前致谢。

客户端app.config

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="ServiceModelMessageLoggingListener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
            <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="ServiceModelTraceListener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add initializeData="c:\users\...\app_messages.svclog"
                type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                <filter type="" />
            </add>
            <add initializeData="c:\users\...\app_tracelog.svclog"
                type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
                <filter type="" />
            </add>
        </sharedListeners>
    </system.diagnostics>
    <system.serviceModel>
        <diagnostics>
            <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
                logMessagesAtTransportLevel="true" />
        </diagnostics>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding" closeTimeout="01:50:00" openTimeout="01:50:00"
                    receiveTimeout="01:50:00" sendTimeout="01:50:00" maxBufferPoolSize="2147483647"
                    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession inactivityTimeout="00:20:00" />
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://localhost:9000/RecruitAidService"
                behaviorConfiguration="endpointBehavior" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding" contract="RecruitAidClientService.IRecruitAidService"
                name="NetTcpBinding" />
        </client>
      <behaviors>
        <endpointBehaviors>
          <behavior name="endpointBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>
</configuration>

服务/服务器app.config

UpdateApplicantUpdateBy(pSession, applId);

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="c:\users\...\app_messages.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp, Callstack">
        <filter type="" />
      </add>
      <add initializeData="c:\users\...\app_tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
  <runtime>
    <loadFromRemoteSources enabled="true"/>
   </runtime>
      <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <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>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
        logMessagesAtTransportLevel="true" />
    </diagnostics>
    <services>
      <service name="RecruitAidServer.RecruitAidService">
        <clear />
        <endpoint address="net.tcp://localhost:9000/RecruitAidService"
          binding="netTcpBinding" bindingConfiguration="" name="NetTcpBinding"
          contract="RecruitAidServer.IRecruitAidService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/RecruitAidServer/Service1/" />
          </baseAddresses>
          <timeouts closeTimeout="00:01:50" />
        </host>
      </service>
    </services>

    <bindings>
      <basicHttpBinding>
        <binding name="NetTcpBinding" closeTimeout="01:50:00" openTimeout="01:50:00"
          receiveTimeout="01:50:00" sendTimeout="01:50:00" maxBufferPoolSize="21474836470000"
          maxBufferSize="2147483647" maxReceivedMessageSize="21474836470000"
          transferMode="Buffered" messageEncoding="Mtom">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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="False" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="endpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

服务器端的服务配置应该类似于

<endpoint address="net.tcp://localhost:9000/RecruitAidService"
    binding="netTcpBinding" bindingConfiguration="NetTcpBinding"
    name="NetTcpBinding" behaviorConfiguration="endpointBehavior"
    contract="RecruitAidServer.IRecruitAidService" />

和绑定

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding" closeTimeout="01:50:00" openTimeout="01:50:00"
      receiveTimeout="01:50:00" sendTimeout="01:50:00" maxBufferPoolSize="21474836470000"
      maxBufferSize="2147483647" maxReceivedMessageSize="21474836470000"
      transferMode="Buffered" messageEncoding="Mtom">
      <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
    </binding>
  </netTcpBinding>
</bindings>