代码之家  ›  专栏  ›  技术社区  ›  Hasan Zubairi

Wcf大数据文件

  •  0
  • Hasan Zubairi  · 技术社区  · 6 年前

    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
      </appSettings>
      <connectionStrings>
        <add name="ApplicationServices" connectionString="data source=LAPTOP-7JC2DRGE;Integrated Security=true;Initial Catalog=ExamDB" providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.6.1"/>
        <httpRuntime targetFramework="4.6.1" />
        <httpModules>
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
        </httpModules>
        <membership>
          <providers>
            <clear />
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
          </providers>
        </membership>
        <roleManager enabled="true">
          <providers>
            <clear />
            <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
            <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
          </providers>
        </roleManager>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="serviceBehaviors">
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="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="web" >
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <services>
          <service name="ExamService.ExamService" behaviorConfiguration="serviceBehaviors">
            <endpoint address="" contract="ExamService.IExamService" binding="webHttpBinding" behaviorConfiguration="web" ></endpoint>
          </service>
        </services>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https"  />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="ApplicationInsightsWebTracking"/>
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
            preCondition="managedHandler"/>
        </modules>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
        <validation validateIntegratedModeConfiguration="false"/>
      </system.webServer>
    
    </configuration>
    

    我在这个网站上尝试了以前的答案,但似乎都不起作用。我使用的是框架4.6。

    1 回复  |  直到 6 年前
        1
  •  0
  •   PhilS    6 年前

    我怀疑您需要为webHttpBinding绑定添加绑定元素,并将maxReceivedMessageSize设置为较大的值。默认值为65536字节。

    这需要在web.config的system.serviceModel节点中设置

    下面是一个设置为5MB的xml示例

    <bindings>
      <webHttpBinding>
        <binding name="largeMessage" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    

    能否尝试更新服务节点以明确使用绑定配置(bindingConfiguration属性等于bindingName属性)。我不认为这是真的需要,因为只有一个绑定,但让我们尝试显式。

    <services>
      <service name="ExamService.ExamService" behaviorConfiguration="serviceBehaviors">
        <endpoint address="" contract="ExamService.IExamService" binding="webHttpBinding" bindingConfiguration="largeMessage" behaviorConfiguration="web" ></endpoint>
      </service>
    </services>
    

    使现代化

    namespace LargeMessageService
    {
        [ServiceContract]
        public interface ILobService
        {
    
            [OperationContract]
            [WebGet]
            string EchoWithGet(string s);
    
            [OperationContract]
            [WebInvoke]
            string EchoWithPost(string s);
        }
    
        public class LobService : ILobService
        {
            public string EchoWithGet(string s)
            {
                return "You said " + s;
            }
    
            public string EchoWithPost(string s)
            {
                return "You said " + s;
            }
        }
    }
    

    当我有一个没有定义绑定的配置时,它以413失败,正如您所看到的。当我添加装订时,它起作用了。带绑定的完整web.config文件:

    <appSettings>
      <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
      <compilation debug="true" targetFramework="4.6.1" />
      <httpRuntime targetFramework="4.6.1"/>
    </system.web>
    <system.serviceModel>
      <behaviors>
        <serviceBehaviors>
          <behavior name="serviceBehaviors">
            <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
            <serviceMetadata httpGetEnabled="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="true"/>
          </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
          <behavior name="web" >
            <webHttp></webHttp>
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <bindings>
        <webHttpBinding>
          <binding name="largeMessage" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
            <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
            <security mode="None"/>
          </binding>
        </webHttpBinding>
      </bindings>
      <services>
        <service name="LargeMessageService.LobService" behaviorConfiguration="serviceBehaviors">
          <endpoint address="" contract="LargeMessageService.ILobService" binding="webHttpBinding" bindingConfiguration="largeMessage" behaviorConfiguration="web" ></endpoint>
          <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </service>
      </services>
      <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https"  />
      </protocolMapping>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
      <!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        -->
      <directoryBrowse enabled="true"/>
    </system.webServer>
    

    我使用IISExpress,通过Postman调用EchoWithPost操作,并使用xml调用它。

    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Hello</string>
    

    用大字符串替换“Hello”(约500K)

    试着让这一个工作,如果它是一个案件,试图找出这一个和你的一个区别。让我知道你进展如何。