最近在做WCF文件上传,一开始能否上传下于64K的文件,后来我修改了配置文件,结果报错为
“远程服务器返回了意外响应: (400) Bad Request” 和 “套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的” 两个错误。
下面我为这两个问题贴出具体配置代码,求大神指点。感激不尽。
/******************只能上传小于64KB文件***********************/ <!--客户端配置--> <basicHttpBinding> <binding name="FileOperateUtilBinding" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:20:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> <behavior name="FileOperateBehavior"> <clientCredentials> <serviceCertificate> <authentication certificateValidationMode="None"/> </serviceCertificate> </clientCredentials> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <!--附件上传下载服务--> <endpoint address="http://localhost:6080/Affix/FileOperateUtil.svc" binding="basicHttpBinding" bindingConfiguration="FileOperateUtilBinding" contract="SklEIP.Facade.IFileOperateUtil" name="BasicHttpBinding_IFileOperateUtil"> <identity> <dns value="localhost" /> </identity> </endpoint> <!--EndPointConfig--> public const string FileOperateUtil = "BasicHttpBinding_IFileOperateUtil"; <!--服务端配置--> <basicHttpBinding> <binding name="FileOperateUtilBinding" closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> </binding> </basicHttpBinding> <behavior name="FileOperateBehavior"> <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false --> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <!--附件上传下载服务--> <service behaviorConfiguration="FileOperateBehavior" name="SklEIP.WCFLibrary.FileOperateUtil"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="FileOperateUtilBinding" contract="SklEIP.Facade.IFileOperateUtil"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> /******************只能上传小于64KB文件***********************/
/*************************目前配置*************************************/ <!--客户端配置--> <basicHttpBinding> <binding name="FileOperateUtilBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="9223372036854775807" messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> <behavior name="FileOperateBehavior"> <clientCredentials> <serviceCertificate> <authentication certificateValidationMode="None"/> </serviceCertificate> </clientCredentials> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <endpoint address="http://localhost:6080/Affix/FileOperateUtilService.svc" binding="basicHttpBinding" bindingConfiguration="CustomWsHttpBinding" contract="SklEIP.Facade.IFileOperateUtil" name="BasicHttpBinding_IFileOperateUtilService"> <identity> <dns value="localhost" /> </identity> </endpoint> <!--服务端配置--> <basicHttpBinding> <binding name="FileOperateUtilBinding" maxReceivedMessageSize="2147483647" messageEncoding="Mtom" transferMode="Streamed" sendTimeout="00:10:00"> </binding> </basicHttpBinding> <behavior name="FileOperateBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> <!--附件上传下载服务--> <service behaviorConfiguration="FileOperateBehavior" name="SklEIP.WCFLibrary.FileOperateUtilService"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="FileOperateUtilBinding" contract="SklEIP.Facade.IFileOperateUtil"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> /*************************目前配置*************************************/
修改了什么?
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"