Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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服务发送超过13 Mb的数据(超过最大请求长度)_C#_Wcf - Fatal编程技术网

C# 我能';无法向WCF服务发送超过13 Mb的数据(超过最大请求长度)

C# 我能';无法向WCF服务发送超过13 Mb的数据(超过最大请求长度),c#,wcf,C#,Wcf,我无法向WCF服务发送超过13MB的数据。我得到超过最大请求长度的异常 下面是CreateServiceHost的实现 protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { IssuedSecurityTokenParameters itp = new IssuedSecurityTokenParameters( "htt

我无法向WCF服务发送超过13MB的数据。我得到超过最大请求长度的异常

下面是CreateServiceHost的实现

    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{

 IssuedSecurityTokenParameters itp = new IssuedSecurityTokenParameters(
                   "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");

            itp.IssuerAddress = new EndpointAddress(ConfigManager.ActAsSTS);
            itp.IssuerMetadataAddress = new EndpointAddress(ConfigManager.ActAsSTS + "/mex");

            // Create the security binding element
            SecurityBindingElement sbe = SecurityBindingElement.CreateIssuedTokenForCertificateBindingElement(itp);
            sbe.MessageSecurityVersion =
                MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;


            // Create the HTTP transport binding element
            HttpTransportBindingElement httpBe = new HttpTransportBindingElement();
           httpBe.MaxReceivedMessageSize = httpBe.MaxBufferPoolSize = Constants.MaxFileSize;


           TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement();
            XmlDictionaryReaderQuotas quotas = encodingElement.ReaderQuotas;
            quotas.MaxArrayLength = quotas.MaxBytesPerRead = quotas.MaxStringContentLength = quotas.MaxNameTableCharCount = quotas.MaxDepth = (int)Constants.MaxFileSize;

            // Create the custom binding using the prepared binding elements
            CustomBinding binding = new CustomBinding(sbe, encodingElement, httpBe);


            EndpointAddress endpointAddress = new EndpointAddress(new Uri(ConfigManager.BaseAddress));
            ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription, binding, endpointAddress);
            host.Description.Endpoints.Add(endpoint);


            host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My,
                X509FindType.FindByThumbprint, ConfigManager.ServiceCertificateThumbprint);
}
Constants.MaxFileSize=20971520(20 Mb=20*1024*1024)

设置了所有必要的设置MaxReceivedMessageSize、MaxBytesPerRead…


如果我正确理解您想要实现的目标,那么web.config文件中也有
设置-您想要创建接收大文件上传的WCF服务

如果是这样,也许使用绑定可以帮助您实现目标

不久前,我编写了一个服务,它使用类似以下配置接受大文件上传:

<netTcpBinding>
 <binding name="netTcpStreaming" sendTimeout="00:15:00" transferMode="Streamed" maxReceivedMessageSize="2147483648">
          <security mode="None" />
  </binding>
</netTcpBinding>

这只是一个偶然的机会,因为我以前很少使用WCF,但由于您使用HTTP作为传输工具,是否可能对消息进行base64编码,从而将13 MB的实际数据编码为20 MB?我想base64通常会导致尺寸增加30%,所以可能不是这样。