调用WebService的方法读取图片

切克瑙 2014-03-21 10:42:17
读取照片没做过,不了解。这是网上查找的资料做的,但客户段要怎么写,实在搞不出来了 救命..
WebService里读取方法的代码

[WebMethod]
public byte[] GetImage(int attachment_source_id, int attachment_type)
{
C_Attachment item = GetAttachment(attachment_source_id, attachment_type);
string fullPath = GetFullPath(item);
if (String.IsNullOrEmpty(fullPath))
{
throw new ArgumentNullException("文件路径不能为空!");
}
else
{
return GetBinaryImage(fullPath);
}
}

public C_Attachment GetAttachment(int attachment_source_id, int attachment_type)
{
return attachment.GetAttachment(attachment_source_id, attachment_type);
}

private string GetFullPath(C_Attachment item)
{
//图片的根目录 /UploadPath/
string rootPath = ConfigurationManager.AppSettings["UploadPath"];
return Server.MapPath(rootPath + "/" + item.Attachment_path);
}



我写的客户端的代码【但是不对】

TPWScreenInDoor.ScreenInDoorSoapClient _screenIn = new TPWScreenInDoor.ScreenInDoorSoapClient();
var item = _screenIn.GetListByScreenInDoor(tbCode.Text);

#region 读取前几个站点拍摄的照片
TPWAttachment.AttachmentServiceSoapClient atta = new TPWAttachment.AttachmentServiceSoapClient();
C_Attachment _att = new C_Attachment();
byte[] attachemnt = atta.GetImage(item.Attachment_source_id, item.Attachment_type);
#region
//using (FileStream fileStream = new FileStream(_att.Attachment_path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
//{
// byte[] attachemnt = atta.GetImage(_att.Attachment_source_id, _att.Attachment_type);
// byte[] bytes = new byte[1024];
// int r = fileStream.Read(attachemnt, 0, attachemnt.Length);
// while (r > 0)
// {
// fileStream.Write(attachemnt, 0, r);
// Console.Write("*");
// r = fileStream.Read(attachemnt, 0, attachemnt.Length);
// }
//}
#endregion
Image img = null;
for (int i = 0; i < attachemnt.Length - 1; i++)
{
MemoryStream ms = new MemoryStream(attachemnt[i]);
img = Image.FromStream(ms);
}
pbIndoor.Image = img;
#endregion

this.tbCode.Text = item.Tv_code;
this.tbBuyCompany.Text = item.Ts_buycompany_text;
this.tbCoalkind.Text = item.Ts_coalkind_text;
this.tbVelhideNumber.Text = item.Tv_vehicle_number;

照片有多张,我客户端应该怎么写...实习生求救...大神们救命呀
...全文
405 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyun0112 2014-03-21
  • 打赏
  • 举报
回复
循环atta.GetImage,传不同的id,得到不同的图片
切克瑙 2014-03-21
  • 打赏
  • 举报
回复
引用 2 楼 feiyun0112 的回复:
GetImage一次只得一张图片吧, MemoryStream ms = new MemoryStream(attachemnt); ***************************************************************************** 签名档: http://feiyun0112.cnblogs.com/
嗯 应该怎么做呢在客户端
feiyun0112 2014-03-21
  • 打赏
  • 举报
回复
GetImage一次只得一张图片吧, MemoryStream ms = new MemoryStream(attachemnt);



*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
切克瑙 2014-03-21
  • 打赏
  • 举报
回复
客户端的代码我重新粘一下

TPWScreenInDoor.ScreenInDoorSoapClient _screenIn = new TPWScreenInDoor.ScreenInDoorSoapClient();
            var item = _screenIn.GetListByScreenInDoor(tbCode.Text);

            #region 读取前几个站点拍摄的照片
            TPWAttachment.AttachmentServiceSoapClient atta = new TPWAttachment.AttachmentServiceSoapClient();
            C_Attachment _att = new C_Attachment();
            byte[] attachemnt = atta.GetImage(item.Attachment_source_id, item.Attachment_type);
            
            Image img = null;
            for (int i = 0; i < attachemnt.Length - 1; i++)
            {
                MemoryStream ms = new MemoryStream(attachemnt[i]);
                img = Image.FromStream(ms);
            }
            pbIndoor.Image = img;
            #endregion

            this.tbCode.Text = item.Tv_code;
            this.tbBuyCompany.Text = item.Ts_buycompany_text;
            this.tbCoalkind.Text = item.Ts_coalkind_text;
            this.tbVelhideNumber.Text = item.Tv_vehicle_number;
            this.tbVelhideType.Text = item.Tv_vehicle_type_text;
            this.tbState.Text = item.Tv_state_text;
            this.tbUpaddress.Text = item.Ts_upaddress_text;
            this.tbDriverName.Text = item.Tv_driver_name;
风一样的大叔 2014-03-21
  • 打赏
  • 举报
回复
需要写个循环,循环的条件根据楼主的需要自己设定

12,162

社区成员

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

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