使用Web服务上传大文件时遇到问题. [英] Facing problem while uploading large files with web service.

查看:184
本文介绍了使用Web服务上传大文件时遇到问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试上传大文件(即超过4 MB)时遇到问题,这使我出错.
未终止的字符串或常量.
AttPages/frmAttch.aspx?hsTable = hsAttach''

我在我的web.config文件中包含了以下代码行

I''m facing problem when I''m trying to upload large file i.e. more than 4 mb it is throwing me an error.
unterminated string or constant.
AttPages/frmAttch.aspx?hsTable=hsAttach''

I have included following line of code in my web.config file

<httpRuntime executionTimeout="3600" maxRequestLength="65536"/>


但对我而言毫无用处.

当我使用服务器(Windows Server 2003)上安装的附件Web服务时,我可以上传超过60mb的内容.
但是当我使用安装在本地m/c(Windows Vista)上的Web服务时,上传的文件大小不能超过4mb.
在这两种情况下,网站及其配置文件都相同,只是服务安装位置不同而Web服务相同.
服务器上是否已经有与机器相关的配置要求,而我的本地机器上却没有.
或某种限制.

任何人都可以建议我可能是什么问题.

下面是Web服务的代码段.
公共字符串AttachFile(字符串strFolderPath,字符串strFile,字节[] fileBuffer)
{
FileStream _FileStream = null;
DirectoryInfo _Folder =新的DirectoryInfo(strFolderPath);
if(!_Folder.Exists)//检查文件夹是否存在于给定路径中,否则创建它.
{
_Folder.Create();
_Folder.SetAccessControl(new System.Security.AccessControl.DirectorySecurity(strFolderPath,System.Security.AccessControl.AccessControlSections.Owner));
}
试试
{
_FileStream =新的FileStream(strFolderPath +"\\" + strFile,FileMode.Create);
_FileStream.Write(fileBuffer,0,fileBuffer.Length);
_FileStream.Close();
返回"True";
}
catch(Ex Ex)
{
返回Ex.Message;
}

}
具有以下Web配置文件.


but of no use in my case.

when i''m using attachment webservice which is installed on server(windows server 2003), than I''m able to upload more even more than 60mb.
but when i''m using webservice which is installed on my local m/c (windows vista), than not able to upload more than 4mb.
In both cases website and its config file is same only service installation place is diffrent but web service is same.
Is there any machine related config is required which is already there on server and i dont have it on my local machin.
or kind of restrictions.

can any one suggest me what could be the problem.

Below is the code snippets of web service.
public String AttachFile(string strFolderPath, string strFile, byte[] fileBuffer)
{
FileStream _FileStream = null;
DirectoryInfo _Folder = new DirectoryInfo(strFolderPath);
if (!_Folder.Exists)//Checks if the folder exists in the given path else creates it.
{
_Folder.Create();
_Folder.SetAccessControl(new System.Security.AccessControl.DirectorySecurity(strFolderPath, System.Security.AccessControl.AccessControlSections.Owner));
}
try
{
_FileStream = new FileStream(strFolderPath + "\\" + strFile, FileMode.Create);
_FileStream.Write(fileBuffer, 0, fileBuffer.Length);
_FileStream.Close();
return "True";
}
catch (Exception Ex)
{
return Ex.Message;
}

}
with following webconfig file.

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <appSettings />
    <connectionStrings />
    <system.web>
<authentication mode="Windows" />
<identity impersonate="true" userName="astral\EERADMIN" password="pass@123" />

<customErrors mode="Off" />
<sessionState timeout="1440" />
<httpRuntime maxRequestLength="102400" executionTimeout="240" />
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true" defaultLanguage="c#" />
        <roleManager enabled="true" />
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
  <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
        <directoryBrowse enabled="true" />
    </system.webServer>
</configuration>

推荐答案

将您的maxrequestlength更改为5mb,看看是否没有帮助.

或者,您可以以64K(这是您当前的请求长度)的块的形式发送文件.

或者,您可以重写您的Web服务.

或者,您可以改用FTP.

或者,您可以尝试使用WebClient.UploadFile.

这是您的代码和您的项目.我们只能提出解决方案.
Change your maxrequestlength to 5mb, and see if that doesn''t help.

Or, you could send the file in chunks of 64K (which is your current request length).

Or, you could rewrite your web service.

Or, you could use FTP instead.

Or, you could try using WebClient.UploadFile.

It''s your code, and your project. We can only suggest solutions.


你好Nirbhay,

您的web.config中没有问题.唯一的问题可能是您正在使用Web服务附加文档. Web服务具有局限性,由于其SOAP协议,您不能传递超出数量的数据.


希望对您有帮助.

Pankaj
Hello Nirbhay,

There is no problem in your web.config. only problem that could be is that you are using web service to attach documents. Web service has Limitation that you can not pass data exceed quantity, because of its SOAP protocol.


Hope this will help you.

Pankaj


这篇关于使用Web服务上传大文件时遇到问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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