发送大量数据,WCF服务

问题描述:


嗨,发送大量数据,WCF服务

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

失败的指令是:

roleCliente.SaveStructure(role, ref s);

“角色” 包含自定义对象的列表;该指令在列表足够短时正确工作。

服务器端的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> 
+4

_ “它不工作” _是不是一个错误。什么是确切的例外信息,你尝试过什么? – CodeCaster

+0

我很好奇,当你的意思很大,那有多大? –

+0

我解决了在“basicHttpBinding”下添加一个未命名的绑定。有人解释我为什么吗? – user1047400

如果你想发送在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:大块它自己

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