如何将Image Byte []从WCF服务传输到Application C# [英] How to transfer Image Byte[] from WCF service to Application C#

查看:87
本文介绍了如何将Image Byte []从WCF服务传输到Application C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将人员列表从wcf服务转移到应用程序。但是当我用数据绑定图像数组时,引发了maxReceivedMessageSize问题。我已经给了多个值,但都是徒劳的。



但实际问题不仅仅是因为我必须转移人的搜索结果而且可以有多个记录集返回。所以我必须处理多个图像阵列。



所需解决方案:



我想要一个正确的方法将数据从wcf服务传输到应用程序,以便它可以处理尽可能多的图像数组。



提前致谢。

Bilal Hassan

解决方案

如果图像是一个字节数组

你可以传输图像集合,例如列表< byte []>



在WCF服务的服务合同界面中

你可以定义一个方法,例如

 [OperationContract] 
列表< byte [] > GetImages();





实施可能是例如

  public  List< byte [] >  GetImages()
{
List< byte [] > images = new 列表< byte [] > ();

images.Add( new byte [] {0x20,0x20,0x20 ,0x20,0x20,0x20,0x20});
images.Add( new byte [] {0x20,0x20,0x20,0x20,0x20 ,0x20,0x20});

返回图片;
}





此示例使用虚拟数据,

由您来添加实际数据到列表。


如果你有大量的数据要通过WCF传输,你应该看一下流媒体:



查看 http://msdn.microsoft.com/ en-us / library / ms751463%28v = vs.110%29.aspx [ ^ ]


您应该在下一个类似问题上查看我的答案:

如何将从WCF服务收到的同一类obj转移到应用程序C# [ ^ ]

I am trying to transfer list of persons from wcf service to application. but when i bind image array with data then "maxReceivedMessageSize" issue raised. I have given multiple values but all in vain.

But actual problem is not only this because i have to transfer result of search of person and there can be multiple record set return. So i have to handle multiple Image array.

Solution required:

I want a proper way to transfer data from wcf service to application so that it can handle as many as possible Image arrays.

Thanks in advance.
Bilal Hassan

解决方案

If an image is a byte array
you could transfer an image collection as e.g. List<byte[]>

In the service contract interface of your WCF service
you could define a method e.g.

[OperationContract]
List<byte[]> GetImages();



The implementation could be e.g.

public List<byte[]> GetImages()
{
    List<byte[]> images = new List<byte[]>();

    images.Add(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 });
    images.Add(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 });
            
    return images;
}



This example uses dummy data,
it's up to you to add real data to the list.


If You hav a large amaount of data to transfer via WCF, You should take a look at streaming:

Take a look at http://msdn.microsoft.com/en-us/library/ms751463%28v=vs.110%29.aspx[^]


You should check my answer on the next similar question:
How to transfer same class obj that was received from WCF service to Application C#[^]


这篇关于如何将Image Byte []从WCF服务传输到Application C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆