Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在将文件发送到WCF服务,套接字连接中止_Wcf_C# 4.0_Bytearray_Wcf Binding - Fatal编程技术网

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

正在将文件发送到WCF服务,套接字连接中止,wcf,c#-4.0,bytearray,wcf-binding,Wcf,C# 4.0,Bytearray,Wcf Binding,我有一个WCF服务(服务器),其方法的签名是 public void SetProfilePic(String pSession, Applicant pApplicant) 申请人拥有以下财产: public byte[] Photo { get; set; } 从客户端我得到一个图像并调用SetProfilePic。当图像很小,大约1厘米X 1厘米时,它工作得很好,然而,当图像较大,4厘米X 3厘米时,我得到下面的误差 "The socket connection was aborted

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

public void SetProfilePic(String pSession, Applicant pApplicant)
申请人拥有以下财产:

public byte[] Photo { get; set; }
从客户端我得到一个图像并调用SetProfilePic。当图像很小,大约1厘米X 1厘米时,它工作得很好,然而,当图像较大,4厘米X 3厘米时,我得到下面的误差

"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文件中的最大限制,但是仍然收到相同的错误。我在缓冲模式下使用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>
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>

服务/服务器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>
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>
updateapplicationupdateby(pSession,applId);

服务器端的服务配置应如下所示

<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>


奇怪,配置看起来不错。我提到的唯一一件事是:在服务器端,由于没有指定behaviorConfiguration,endpointBehavior并没有真正应用于服务。对于
bindingConfiguration
,它是空的。您应该将其设置为NetTcpBinding。我也不知道你用哪种装订。您已经配置了basicHttpBinding,但服务使用了NetTcpBinding非常感谢您的帮助。您提供的上述配置解决了该问题。我还删除了messageEncoding=“Mtom”再次感谢。