【发布时间】:2012-05-19 07:49:14
【问题描述】:
我想通过webservice返回一个图像,所以我尝试将数据库中的图像转换为字节,然后从字节转换为base64字符串并将其返回给webservice,我完成了一半但我无法返回整个字符串希望是由于字符串大小的限制或其他原因?
<%@ WebService Language="C#" Class="Service" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string IMAGE(string ID)
{
SqlConnection conn = new SqlConnection("Data Source=NEWCRISP19;Initial Catalog=masselango;Persist Security Info=True;User");
conn.Open();
SqlDataAdapter sdImageSource = new SqlDataAdapter();
sdImageSource.SelectCommand = new SqlCommand("select ImageData from ImagesStore where ImageId=('" + ID + "')", conn);
DataSet dsImage = new DataSet();
sdImageSource.Fill(dsImage);
byte[] blob = (byte[])dsImage.Tables[0].Rows[0][0];
String c = Convert.ToBase64String(blob);
//c = c.Replace(" ", "");
return c;
}
}
web.config 未修改。
帮我检索整个 base64 字符串。
【问题讨论】:
-
不能作为字节数组传回去吗?
-
虽然我需要将我的应用程序进程作为 base64 字符串传递,但我使用了这样的传输方式,尽管它返回了一些要传递的字符限制并且它不会传递整个数据
-
我不知道通过网络服务对刺痛长度的限制(但很高兴被告知不是这样),但是如果您遇到问题,那么我看不出是什么阻止您传递字节数组,然后转换为 base64 字符串 in 客户端应用程序
-
我会使用 DataReader 而不是 DataSet。检查 Web 服务器是否有任何限制。看看能否转回blob并在服务器上显示,确定是传输问题。
-
嘿伙计们,我发现了问题,当它在 iis 之外执行时,它可以准确地返回字符串,当我运行 iis 时它不会返回确切的字符串
标签: c# asp.net web-services iis iis-5