Error “This message cannot support the operation because it has been read”

前端 未结 3 1220
误落风尘
误落风尘 2020-12-30 02:29

I have the same problem that is listed in the following thread.

WSDL first WCF server where client does not send SOAPAction

I performed the steps that are li

3条回答
  •  醉酒成梦
    2020-12-30 03:00

    You should use MessageBuffer.CreateMessage:

    The body of a Message instance can only be consumed or written once. If you wish to consume a Message instance more than once, you should use the MessageBuffer class to completely store an entire Message instance into memory.

    http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messagebuffer.aspx

    Code from my current project:

    public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
        MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
        reply = buffer.CreateMessage();
        Message m = buffer.CreateMessage();
        LogMessage(m, " Response => ");
    }
    

    Add ref for Message param and return new message.

     private Message CreateMessageCopy(ref Message message, XmlDictionaryReader body)
    {
    ...
       message = buffer.CreateMessage();
    

提交回复
热议问题