流是否一个WCF皂帮助客户发送使用较少的内存?较少、内存、客户、WCF

2023-09-06 23:14:31 作者:泪痕残

我有一个通过WCF将数据发送到服务器的Windows移动应用程序。

I have a windows mobile application that sends data via WCF to a server.

它发送的数据有时会超过移动设备上的窗口的极限。我想知道如果流将帮助并不需要持有所有我必须发出在内存中,一旦数据。

The data it sends sometimes exceeds the limit on the windows mobile device. I am wondering if streaming would help not need to hold all the data I must send in memory at once.

下面是一个简单的例子:

Here is a simple example:

[DataContract]
public class MainContract
{
    [DataMember]
    public Guid  ID { get; set; }

    [DataMember]
    public List<SubContract> SubContract { get; set; }
}

[DataContract]
public class SubContract
{
    [DataMember]
    public Guid ID { get; set; }

    [DataMember]
    public string ImageCaption { get; set; }

    [DataMember]
    public Byte[] ImageAsBytes { get; set; }
}

说我有只有1 MainContract 对象。但它有很多在里面转包的对象。 (我的实际情况是更compelex)。

Say I have only 1 MainContract object. But it has a lot of SubContract objects in it. (My real scenario is more compelex).

保存所有 MainContract 的内存是太多的客户端做的。

Holding all of MainContract in memory is too much for the client side to do.

将流媒体让我送过来的丝条发送数据?或者,我还是要缓冲这一切在客户端和流只是帮助与大数据的接收?

Will streaming allow me to send send the data over the wire in pieces? Or do I still have to buffer it all on the client side and the streaming just helps with the receiving of large data?

推荐答案

据我所知,如果你的方法接受一个 MainContract 则需要有完全存储器在客户端,以流的序列化结果向WCF宿主

As far as I know, if your method accepts a MainContract you will need to have that completely in memory on the client side in order to stream the serialized result to the WCF host.

如果加载了一个完整的 MainContract 将在客户端的内存太多,我会调整服务让这样的事情:

If loading up a full MainContract will take too much memory on the client side, I would adjust the service to allow for something like this:

public Guid CreateMainContract(MainContract obj); // return unique id
public Guid CreateSubContract(Guid mainContractToAddTo, SubContract obj);

再修改调用code到pseduo流数据到WCF主机,通过调用上述操作在一个循环的方式。 (很明显,你需要改变它的更新/删除的情况,等等)。

and then modify the calling code to pseduo-stream the data to the WCF host, by means of calling the above operations in a loop. (Obviously, you'll need to change it up for update/delete situations, etc).

 
精彩推荐
图片推荐