将大数据发送到WCF服务

时间:2012-10-05 14:16:25

标签: asp.net wcf


您好,

我正在尝试从客户端应用程序向WCF网站发送自定义数据。当我尝试发送大量数据时,它不起作用。

失败的指令是:

  

roleCliente.SaveStructure(role, ref s);

“role”包含自定义对象列表;当列表足够短时,指令正常工作。

服务器端web.config是:

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime maxQueryStringLength="2097151"/>
  </system.web>

  <system.diagnostics>
        <sources>
           <source name="System.ServiceModel" switchValue="All">
             <listeners>
                  <add name="xmlTraceListener" />
               </listeners>
           </source>
           <source name="System.ServiceModel.MessageLogging" switchValue="All">
               <listeners>
                   <add name="xmlTraceListener" />
               </listeners>
           </source>
       </sources>
       <sharedListeners>
        <add name="xmlTraceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="ClientLogBasic.svclog" />
     </sharedListeners>
     <trace autoflush="true" />
 </system.diagnostics>


  <system.serviceModel>

    <diagnostics>
      <messageLogging maxMessagesToLog="10000" logEntireMessage="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true">
        <filters>
          <clear/>
        </filters>
      </messageLogging>
    </diagnostics>

    <behaviors>
      <endpointBehaviors>
        <behavior name="EndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="CustomBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
          sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFAgency">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFAgency" contract="ServiceReference1.IWCFAgency" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCompetence">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCompetence" contract="ServiceReference1.IWCFCompetence" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCompetenceScheme">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCompetenceScheme"
          contract="ServiceReference1.IWCFCompetenceScheme" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFPerson">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFPerson" contract="ServiceReference1.IWCFCompetenceScheme" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCertificate">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCertificate" contract="ServiceReference1.IWCFCertificate" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFAttitude">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFAttitude" contract="ServiceReference1.IWCFAttitude" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFClassificationType">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFClassificationType"
          contract="ServiceReference1.IWCFClassificationType" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCompetenceDetail">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCompetenceDetail"
          contract="ServiceReference1.IWCFCompetenceDetail" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCompetencyDetail">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCompetencyDetail"
          contract="ServiceReference1.IWCFCompetencyDetail" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFCompetencyScheme">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFCompetencyScheme"
          contract="ServiceReference1.IWCFCompetencyScheme" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFContext">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFContext" contract="ServiceReference1.IWCFContext" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFEducation">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFEducation" contract="ServiceReference1.IWCFEducation" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFEvidence">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFEvidence" contract="ServiceReference1.IWCFEvidence" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFFormativeCredit">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFFormativeCredit"
          contract="ServiceReference1.IWCFFormativeCredit" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFInstructionalEntity">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFInstructionalEntity"
          contract="ServiceReference1.IWCFInstructionalEntity" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFKnowledge">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFKnowledge" contract="ServiceReference1.IWCFKnowledge" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFResponsibility">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFResponsibility"
          contract="ServiceReference1.IWCFResponsibility" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFRole">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFRole" contract="ServiceReference1.IWCFRole" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFRoleScheme">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
          bindingConfiguration="CustomBinding" name="WCFRoleScheme" contract="ServiceReference1.IWCFRoleScheme" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFScale">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          binding="basicHttpBinding" name="WCFScale" contract="ServiceReference1.IWCFScale" />
      </service>
      <service behaviorConfiguration="ServiceBehaviour" name="ServiceReference1.WCFSkill">
        <endpoint address="http://193.205.191.6/WCFSiretCM/WCFSiretCM.svc"
          binding="basicHttpBinding" name="WCFSkill" contract="ServiceReference1.IWCFSkill" />
      </service>
    </services>

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

,而客户端web.config是:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <httpRuntime maxQueryStringLength="2097151"/>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="CustomBinding" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>        
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFAgency" name="BasicHttpBinding_IWCFAgency" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFPerson" name="BasicHttpBinding_IWCFPerson" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFCertificate" name="BasicHttpBinding_IWCFCertificate" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFAttitude" name="BasicHttpBinding_IWCFAttitude" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFClassificationType" name="BasicHttpBinding_IWCFClassificationType" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFCompetence" name="BasicHttpBinding_IWCFCompetence" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFCompetenceDetail" name="BasicHttpBinding_IWCFCompetenceDetail" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFCompetenceScheme" name="BasicHttpBinding_IWCFCompetenceScheme" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFCompetencyDetail" name="BasicHttpBinding_IWCFCompetencyDetail" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding" 
        contract="ServiceReference1.IWCFCompetencyScheme" name="BasicHttpBinding_IWCFCompetencyScheme" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFContext" name="BasicHttpBinding_IWCFContext" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFEducation" name="BasicHttpBinding_IWCFEducation" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFEvidence" name="BasicHttpBinding_IWCFEvidence" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFFormativeCredit" name="BasicHttpBinding_IWCFFormativeCredit" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFInstructionalEntity" name="BasicHttpBinding_IWCFInstructionalEntity" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFKnowledge" name="BasicHttpBinding_IWCFKnowledge" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFResponsibility" name="BasicHttpBinding_IWCFResponsibility" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc"
        behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
        bindingConfiguration="CustomBinding" contract="ServiceReference1.IWCFRole"
        name="BasicHttpBinding_IWCFRole" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" 
        behaviorConfiguration="EndPointBehavior" binding="basicHttpBinding"
        bindingConfiguration="CustomBinding" contract="ServiceReference1.IWCFRoleScheme"
        name="BasicHttpBinding_IWCFRoleScheme" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFScale" name="BasicHttpBinding_IWCFScale" />
      <endpoint address="http://localhost/WCFSiretCM/WCFSiretCM.svc" behaviorConfiguration="EndPointBehavior"
        binding="basicHttpBinding" bindingConfiguration="CustomBinding"
        contract="ServiceReference1.IWCFSkill" name="BasicHttpBinding_IWCFSkill" />
    </client>
  </system.serviceModel>
</configuration>

2 个答案:

答案 0 :(得分:0)

如果你想在WCF中发送大量数据,你可能会使用流模式。

http://msdn.microsoft.com/en-us/library/ms731913.aspx

http://msdn.microsoft.com/en-us/library/ms733742.aspx

或者您可以通过实现多种服务方法(例如

)来使用变通方法并以块的形式传输数据
StartUpload()

SendChunk(byte[] chunk)

EndUpload()

答案 1 :(得分:0)

如果您决定将消息分块,只是增加最大配额或超时,那么确实有两种选择。

选项1:自己分块

选项2:频道分组 http://msdn.microsoft.com/en-us/library/aa717050(v=vs.110).aspx