使用webservice保存文件,文件过大保存失败问题?

冰之规则 2018-03-16 05:41:08

public string SaveFile(string sn, string qty,string file1,string file2,string file3,string file4,string file5)
{

StringBuilder sb = new StringBuilder();
sb.Length = 0;
sb.Append(file1);
sb.Append(file2);
sb.Append(file3);
sb.Append(file4);
sb.Append(file5);
string srcPath = sb.ToString();
if (sn==null || sn=="")
{
return "sn is null";
}
if (srcPath==null)
{
return "srcPath is null";
}
try
{
#region 方案1
DateTime time = DateTime.Now;
string tim = time.ToString("yyyyMMddHHmmss");
string str = srcPath; //convert string 2 stream
byte[] array = new byte[str.Length / 2];
int j = 0;
for (int i = 0; i < str.Length; i += 2)
{
string s = str.Substring(i, 2); //取16进制2位
int n = Convert.ToInt16(s, 16); //将2位16进制,转10进制
array[j] = (byte)Int32.Parse(n.ToString()); //最后结果给字节数组
j++;
}

//创建将要写入的目标位置,
FileStream fg = new FileStream(@"E:\File\" + tim + "_" + sn + "_" + qty + ".tgz", FileMode.Create);
fg.Write(array, 0, array.Length); //将字节数组一次写入,目标位置
fg.Close();

}
catch (Exception ex)
{
return "false!info:"+ ex;
}
return "trueno" + srcPath;
}


这是webservice中的代码,关键问题:“ 在参数位置,接收到的是16进制的元素,但这个参数这里超过20M左右的元素就保存文件失败了”。求正解!

下面是我的web.config配置文件

<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<identity impersonate="false" />
<authentication mode="Forms" />
<compilation targetFramework="4.5" />
<httpRuntime maxRequestLength = "102400000" executionTimeout="3600" />
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>

</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>

...全文
366 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧