1
**Web Config:**
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <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>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <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>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <!--Add refernce to any new service that is to be added
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="EmployeeService.svc" service="PeopleInbox.ServiceLibrary.EmployeeService" />
        <add relativeAddress="LookupService.svc" service="PeopleInbox.ServiceLibrary.LookupService" />
        <add relativeAddress="SecurityService.svc" service="PeopleInbox.ServiceLibrary.SecurityService" />
        <add relativeAddress="EmployerService.svc" service="PeopleInbox.ServiceLibrary.EmployerService" />
      </serviceActivations>
    </serviceHostingEnvironment>-->
    <services>
      <service name="PeopleInbox.ServiceLibrary.EmployeeService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IEmployeeService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/EmployeeService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.AdminService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IAdminService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/AdminService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.LookupService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ILookupService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/LookupService/" />
          </baseAddresses>
        </host>
      </service>
      <service name="PeopleInbox.ServiceLibrary.SecurityService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ISecurityService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/SecurityService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </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>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>
</configuration>

错误 已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

请告诉在哪里设置 maxReceivedMessageSize。我无法创建绑定,也不知道如何使用。我检查了很多教程,但找不到使代码运行的正确答案。谢谢

4

1 回答 1

0

您需要创建绑定配置并将其分配给bindingConfiguration服务上的属性。

要创建绑定,请在<system.serviceModel>配置文件的部分中添加一个部分,例如:

<bindings>
  <basicHttpBinding>
    <binding name="MyHttpBinding" 
             maxReceivedMessageSize="2147483647" />
  </basicHttpBinding>
</bindings>

bindingConfiguration然后在您的服务端点中,您通过元素上的属性分配上述绑定<endpoint>。例如:

<endpoint address="" binding="basicHttpBinding" 
          bindingConfiguration="MyHttpBinding"
          contract="PeopleInbox.ServiceLibrary.IAdminService">

这将导致定义的端点使用您定义的绑定(其maxReceivedMessageSize值设置为属性的最大值 (Int32.MaxValue),而不是basicHttpBinding.

于 2018-08-31T10:08:33.397 回答