2009-05-22 103 views
3

我正在使用WCF通過線路發送一些Linq對象。我想要使​​用消息日誌記錄或跟蹤來記錄消息大小。我不想要,或者有能力使用配置文件來設置它。我正在努力弄清楚如何以編程方式進行此操作。我不在乎這是否發生在客戶端。我控制着兩者。記錄WCF消息大小

有沒有人有這樣做的經驗?

回答

3

Marc的權利,Message Inspectors將允許您執行此操作。創建一個類:實現IDispatchMessageInspector。下面的方法將在您可以實現代碼來操縱請求消息的地方提供。

Public Function AfterReceiveRequest(ByRef request As System.ServiceModel.Channels.Message, ByVal channel As System.ServiceModel.IClientChannel, ByVal instanceContext As System.ServiceModel.InstanceContext) As Object Implements System.ServiceModel.Dispatcher.IDispatchMessageInspector.AfterReceiveRequest 
    'Output the request message to immediate window 
    System.Diagnostics.Debug.WriteLine("*** SERVER - RECEIVED REQUEST ***") 
    System.Diagnostics.Debug.WriteLine(request.ToString()) 

    Return Nothing 
End Function 

此外,以下Link也可能會提供一些幫助。

好運