流式传输 WCF Soap 是否有助于客户端使用更少的内存进行发送?

发布于 2024-09-28 15:37:59 字数 779 浏览 0 评论 0原文

我有一个 Windows Mobile 应用程序,它通过 WCF 将数据发送到服务器。

它发送的数据有时会超出 Windows Mobile 设备上的限制。我想知道流式传输是否有助于不需要将我必须立即发送到内存中的所有数据保存起来。

这是一个简单的例子:

[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 对象。但它里面有很多 SubContract 对象。 (我的真实场景更复杂)。

对于客户端来说,将所有 MainContract 保存在内存中的工作量太大。

流式传输是否允许我通过网络分段发送数据?或者我仍然需要在客户端缓冲所有数据,而流式传输只是有助于接收大数据?

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; }
}

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2024-10-05 15:37:59

据我所知,如果您的方法接受 MainContract,您将需要将其完全存储在客户端的内存中,以便将序列化结果流式传输到 WCF 主机。

如果加载完整的 MainContract 会在客户端占用太多内存,我会调整服务以允许类似这样的事情:

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

然后修改调用代码以将数据伪流式传输到 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.

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);

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文