【问题标题】:Getting the underlying stream from a wcf streaming webservice从 wcf 流式 Web 服务获取底层流
【发布时间】:2011-03-09 09:20:55
【问题描述】:

我正在 WCF 中构建流式 Web 服务,但在访问底层流时遇到问题。

我正在实施基于 wsdl 的现有合同,但我想让服务流式传输。由于我无法更改合同,因此我无法使用 Stream 作为参数选项(因为这会更改合同)。

所以我决定使用 Message 作为参数并返回。这完美无缺。

但我想访问 Stream 对象(它必须位于 Message 对象或其属性中的某个位置)。但是 Message 给我的唯一东西是 XmlDictionaryReader,它不允许访问 Stream。

public Message GetMessage(Message message)
    {
        // We need some way to access the underlying stream from the message - the GetReaderAtBodyContents is not usable
        XmlDictionaryReader reader = message.GetReaderAtBodyContents();
        CopyReaderToFile(reader);
        return Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IStreamingService/GetMessageResponse", "Hej med dig fra GetMessage. MessageLength ");
    }

上面显示了我的服务实现。 XmlDictionaryReader 的主要问题是它无法让我访问客户端发送的精确数据 - 换句话说,我无法在服务上重现来自客户端的内容。这很糟糕,因为我无法验证 MessageHeaders 中存在的签名。

那么有没有办法访问底层流?这可以通过行为来实现吗?

提前致谢

【问题讨论】:

    标签: wcf web-services streaming


    【解决方案1】:

    问题在于流不是由消息本身提供,而是由底层消息编码器提供。在抽象 MessageEncoder 类的两个方法中可以看到:

    流仅在频道级别可用,不在消息中。另一个问题是流无法与消息安全性相结合——因此您不能使用任何内置签名等。

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多