简体   繁体   English

WCF大数据文件

[英]Wcf large data file

I am trying to upload an image file in base64 format from a angular app. 我正在尝试从角度应用程序上传base64格式的图像文件。 The app is working fine for small images but wcf is giving error of entity too large error for images larger then 200kb. 该应用程序适用于较小的图像,但wcf对于大于200kb的图像给出了实体错误,误差太大。 My webconfig file is like this. 我的webconfig文件是这样的。

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

I tried previous answers on this site but none seems to be working. 我在此网站上尝试过以前的答案,但似乎没有任何作用。 I am using framework 4.6. 我正在使用框架4.6。

I suspect you need to add a binding element for the webHttpBinding binding and set maxReceivedMessageSize to something large. 我怀疑您需要为webHttpBinding绑定添加一个绑定元素,并将maxReceivedMessageSize设置为较大值。 The default value is 65536 bytes. 默认值为65536字节。

This needs to be set in the system.serviceModel node in the web.config 这需要在web.config的system.serviceModel节点中设置

Below is an example xml set to 5MB 下面是将XML设置为5MB的示例

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

Could you try updating the services node to explicitely use the binding config (bindingConfiguration attribute equals the binding name attribute). 您能否尝试更新服务节点以显式使用绑定配置(bindingConfiguration属性等于绑定名称属性)。 I don't think this is really required as there is only one binding but lets try being explicit. 我认为这并不是真正需要的,因为只有一个绑定,但请尝试明确。

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

UPDATE UPDATE

Not sure whats going on here. 不知道这是怎么回事。 I made a quick dummy service to replicate the problem. 我做了一个快速的虚拟服务来复制该问题。

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

When I had a configuration without the binding defined it failed with a 413 as you are seeing. 如您所见,当我有一个未定义绑定的配置时,它失败并显示413。 When I added the binding it worked. 当我添加绑定时,它起作用了。 My full web.config with binding: 我完整的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>

I was using IISExpress and calling it through Postman by calling the EchoWithPost operation with an xml. 我使用的是IISExpress,并通过带XML的EchoWithPost操作通过邮递员进行调用。

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

replacing 'Hello' with a large string (approx 500K) 用大字符串替换“ Hello”(大约500K)

Try getting this one to work and if it does its a case of trying to work out the difference between this one and your one. 尝试使此功能正常运行,如果确实如此,则尝试找出此功能与您的功能之间的区别。 Let me know how you get on. 让我知道你是怎么办的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM