【问题标题】:Retrieving the MessageId automatically set by WCF when using WSHttpBinding使用 WSHttpBinding 时检索 WCF 自动设置的 MessageId
【发布时间】:2010-11-08 16:48:35
【问题描述】:

我使用 WCF 来使用尊重 WS 表单的 Web 服务(然后我使用 WSHttpBinding 绑定)。此表单涉及在soap 请求的标头中设置MessageID,并且在RelatesTo 字段的响应标头中存在相同的ID。我想记录我与此 MessageId 一起发出的请求,但找不到检索 WCF 设置的 messageId 的方法,我可以手动设置它。我设法通过在字段上设置正确的属性来从响应中获取它,但是在请求上这样做让我设置它,但似乎 WCF 覆盖它并且在调用后不让我访问新值事件。

有什么想法吗?

【问题讨论】:

    标签: c# wcf wshttpbinding wcf-wshttpbinding


    【解决方案1】:

    我也没有找到方法来检索自动设置的消息 ID,但是您可以轻松地手动设置它:

    using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IContextChannel)base.Channel))
        {
            m_lastMessageId = new System.Xml.UniqueId();
            System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.MessageId = m_lastMessageId;
            // call here the request
        }
    

    希望有帮助

    【讨论】:

    • 谢谢,我对 MessageInterceptor 做了同样的事情,但您的解决方案更简单。
    猜你喜欢
    • 2018-10-08
    • 2013-08-09
    • 2017-06-14
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    相关资源
    最近更新 更多