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

前端 未结 3 1221
误落风尘
误落风尘 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:06

    Dmitry Harnitski's answer does not work if you are debugging the service (It will give you a "This message cannot support the operation because it has been copied." error.)

    This works even in debug mode:

    XmlDictionaryReader GetReader(ref Message message)
    {
        MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);
        message = buffer.CreateMessage();
        newMessage = buffer.CreateMessage();
        XmlDictionaryReader rv = buffer.CreateMessage().GetReaderAtBodyContents();
        buffer.Close();
        return rv;
    }
    
    static System.ServiceModel.Channels.Message newMessage = null;
    static System.ServiceModel.Channels.Message lastMessage = null;
    
    public string SelectOperation(ref System.ServiceModel.Channels.Message message)
    {
        try
        {
            if(message == lastMessage)
                message = newMessage;
    
            XmlDictionaryReader bodyReader = GetReader(ref message);
    
            lastMessage = message;
    
            XmlQualifiedName lookupQName = new XmlQualifiedName(bodyReader.LocalName, bodyReader.NamespaceURI);
            if (dispatchDictionary.ContainsKey(lookupQName))
            {
                return dispatchDictionary[lookupQName];
            }
            else
            {
                return null;
            }
        }
        catch(Exception ex)
        {
            throw ex;
        }
    }
    

提交回复
热议问题