通过webservice返回大型字符串时iis出错

时间:2012-05-19 07:49:14

标签: c# asp.net web-services iis iis-5

我想通过webservice返回一个图像,所以我试图将数据库中的图像转换为字节,然后从byte转换为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字符串。

1 个答案:

答案 0 :(得分:0)

我所理解的是您将数据库中的图像存储为二进制文件,并且您想立即检索它。

如果您需要,请查看此链接Insertion and Retrieval of image in binary