0

我想通过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 字符串。

4

1 回答 1

0

我的理解是您已将图像作为二进制存储在数据库中,您现在想检索它。

如果那是您想要的,请检查此链接插入和检索二进制图像

于 2012-05-19T08:04:36.613 回答