0

如何将 ReadMessage 和 WriteMessage 映射到可以控制类库之外的消息编码的事件?

public class CustomMessageEncoder:MessageEncoder
{
    public delegate Message ReadMessage_dlg(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType);
    public delegate Message ReadMessage_dlg(System.IO.Stream stream, int maxSizeOfHeaders, string contentType);
    public static event ReadMessage_dlg OnReadMessage;
    public delegate ArraySegment<byte> WriteMessage_dlg(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset);
    public delegate void WriteMessage_dlg(Message message, System.IO.Stream stream);
    public static event WriteMessage_dlg OnWriteMessage;
    .
    .
    .

    public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
    {
        throw new NotImplementedException();
    }

    public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)
    {
        throw new NotImplementedException();
    }

    public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
    {
        throw new NotImplementedException();
    }

    public override void WriteMessage(Message message, System.IO.Stream stream)
    {
        throw new NotImplementedException();
    }

}

我只想要 StrongType (没有动态/参数对象 [] ) onReadMessage 和 onWriteMessage 事件有没有办法重载可以接受两个方法的委托/事件?

4

1 回答 1

0

这是通常的要求,我想。你为什么不尝试这样做的标准方法?例如,在您的库外代码寄存器中的某处:

 OnWriteMessage += new WriteMessage_dlg(myMessage, myStream);

并在每个特定的 MessageEncoder 读/写方法调用 delegate.invoke?

 public override void WriteMessage(Message wcfMessage, Stream stream) {
   OnWriteMessage.Invoke();
 }
于 2013-06-03T23:04:53.217 回答