Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WCF Web.config中放置绑定信息的位置_C#_Wcf - Fatal编程技术网

C# 在WCF Web.config中放置绑定信息的位置

C# 在WCF Web.config中放置绑定信息的位置,c#,wcf,C#,Wcf,我收到错误“远程服务器返回意外响应:(413)请求实体太大。” 我的Web.Config文件是XML <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web>

我收到错误“远程服务器返回意外响应:(413)请求实体太大。

我的Web.Config文件是XML

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <!-- 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>

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

</configuration>


请指导我如何增加内存大小以及缓冲区、消息接收和发送大小。

首先,我们必须在WCF服务的Web.config的ServiceModel中定义绑定

<bindings>
  <basicHttpBinding>
    <binding name="PowerTransmissionBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="StreamedRequest" messageEncoding="Mtom" >
      <readerQuotas maxDepth="32" maxBytesPerRead="200000000"
       maxArrayLength="200000000" maxStringContentLength="200000000" />
    </binding>
  </basicHttpBinding>
</bindings>

然后我们必须定义端点

<services>
  <service name="DataTestingWCF.Service1">
    <endpoint
       address="processData" binding="basicHttpBinding"
       bindingConfiguration="PowerTransmissionBinding"
       contract="DataTestingWCF.IService1"  />
  </service>
</services>

之后,我们必须在客户端应用程序App.config中建立这个新绑定

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" sendTimeout="00:10:00"
                 messageEncoding="Mtom" transferMode="StreamedRequest" />
      </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:8099/Service1.svc/processData"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="SuperService.IService1" name="BasicHttpBinding_IService1" />
    </client>
</system.serviceModel>

通过这一点,我们可以实现绑定

在此,我将介绍wcfweb.config XML

    <?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
                 maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="StreamedRequest" messageEncoding="Mtom" >
          <readerQuotas maxDepth="32" maxBytesPerRead="200000000"
           maxArrayLength="200000000" maxStringContentLength="200000000" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service name="DataTestingWCF.Service1">
        <endpoint
           address="myAddress" binding="basicHttpBinding"
           bindingConfiguration="MybasicBinding"
           contract="DataTestingWCF.IService1"  />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <!-- 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>

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

</configuration>

到目前为止,您都做了些什么来确定解决方案。理想情况下,您至少应该在stackoverflow中查找这个问题