WCF文件上传错误 [英] WCF File Upload Error

查看:120
本文介绍了WCF文件上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



使用WCF服务上传文件时遇到问题.
下面是错误消息:

远程服务器返回了意外的响应:(400)错误的请求."

Hi,

I am facing an issue while uploading a file using WCF service.
Below is the error message:

"The remote server returned an unexpected response: (400) Bad Request."

<br />
 protected void btnUploadDocument_Click(object sender, EventArgs e)<br />
        {<br />
            DRServiceReference.IDocumentService proxy = new DRServiceReference.DocumentServiceClient();<br />
            UploadDocumentRequest uploadDocumentRequest = new UploadDocumentRequest();<br />
            uploadDocumentRequest.DocumentName = txtFileName.Text;<br />
            uploadDocumentRequest.RepositoryId = 1;<br />
            uploadDocumentRequest.DocumentBytes = StreamFile(txtFileName.Text);<br />
            UploadDocumentResponse uploadDocumentResponse = null;<br />
            uploadDocumentResponse = proxy.UploadDocument(uploadDocumentRequest);<br />
            int documentId = uploadDocumentResponse.DocumentId;<br />
            lbldocumentId.Text = Convert.ToInt32(documentId).ToString();<br />
            if (uploadDocumentResponse.Errors != null)<br />
            {<br />
                string errorMessage = uploadDocumentResponse.Errors[0].Description;<br />
                lblError.Text = "Error : " + errorMessage;<br />
                lbldocumentId.Text = string.Empty;<br />
            }<br />
            if (uploadDocumentResponse.Warnings != null)<br />
            {<br />
                string warningDescription = uploadDocumentResponse.Warnings[0].Description;<br />
            }<br />
        }<br />
        #endregion<br />



请提出建议,因为我无法为此找到解决方案.我已经增加了配置文件中"maxReceivedMessageSize"的大小.它适用于较小的文件,但大于55Kb的文件会出错).



Please suggest as I am not able to find solution for this. I have already increased the size of "maxReceivedMessageSize" in config file. It is working for small size files but giving error for files greater then 55Kb).

推荐答案

作为第一个响应,我说你不应该这样做.您应该分块上传文件.我一直在使用基于WCF的文件服务器在大西洋和太平洋发送多GB的磁盘映像.但是,您可以将大小增加到大于55k.我一直在处理1mb的块.

通常情况下,问题可能出在配置文件中.这是一个绑定标签,可用于接收1mb的文件.

As a first response, I would say that you should not do that. You should upload files in chunks. I have been using a WCF based file server to send multi-Gigabyte disk images across the Atlantic and Pacific. However you can increase your size to considerably larger than 55k. I have been working with 1mb chunks.

As is very often the case the problem probably lies in the configuration files. Here is a binding tag that works for recieving files of 1mb.

<pre><netTcpBinding><br />
               <binding name="tcp" closeTimeout="00:01:00" openTimeout="00:01:00"<br />
                   receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"<br />
                   transferMode="Buffered" transactionProtocol="OleTransactions"<br />
                   hostNameComparisonMode="StrongWildcard" listenBacklog="10"<br />
                   maxBufferPoolSize="524288" maxBufferSize="6553600" maxConnections="10"<br />
                   maxReceivedMessageSize="65536"><br />
                   <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="1638400"<br />
                       maxBytesPerRead="4096" maxNameTableCharCount="16384" /><br />
                   <reliableSession ordered="true" inactivityTimeout="00:10:00"<br />
                       enabled="false" /><br />
                   <security mode="Transport"><br />
                       <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /><br />
                       <message clientCredentialType="Windows" /><br />
                   </security><br />
               </binding><br />
           </netTcpBinding></pre>



maxBufferSizemaxReceivedMessageSizemaxArrayLength是您应该关注的.您需要确保所有组件都愿意接受您要发送的大小的文件.另外,请使用netTcpBinding作为提示.性能差异非常显着.
我希望这会有所帮助



maxBufferSize ,maxReceivedMessageSize and maxArrayLength are the one''s you should be concerned with. You need to make sure that all of the components are willing to accept files of the size that you want to send. Also as a worthy tip, use the netTcpBinding. The performance difference is very significant.
I hope that this was helpful


这篇关于WCF文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆