开发者

access context-informationes from IParameterInspector (WCF)

开发者 https://www.devze.com 2023-02-03 10:48 出处:网络
I try to log all parameters for all requests of an WCF-service. For this i use the \"IParameterInspector\" with is implemented and works so far.

I try to log all parameters for all requests of an WCF-service. For this i use the "IParameterInspector" with is implemented and works so far.

public class ParameterInspector_for_RequestLogging : IParameterInspector
{
    #region IParameterInspector Members

    public void AfterCall(string operationName, object开发者_JAVA百科[] outputs, object returnValue, object correlationState) {
            //Note: correlationState contains an object with contains the inputValues
            //...
            log.WriteEntry(
                new LogData(
                    String.Format("          Req={0}, Time: {1}ms, Input-Parameter: '{2}', Output-Parameter: '{3}', ReturnValue: '{4}'"
                        , operationName
                        , Environment.TickCount - correlationStateData.RequestStartAt
                        , String.Join("','", inputParameter.ToArray())
                        , String.Join("','", outputParameter.ToArray())
                        , returnValue.ToString()
                        )
                    )
                );

    }
}

with output:

Req=ABC, Time: 500ms, Input-Parameter: '123,ABC,zzz,55', Output-Parameter: '0', ReturnValue: '0'"

So i have 2 problems. 1. How i can find the right names of the input and output parameters. 2. How can i pasted context informationen / How can i access context informations. (Like username)

i try to produce the following output:

User: CurrentUser (UserNumber) - Req=ABC, Time: 500ms
  , Input-Parameter: '<int32>para1: 123, <string>Para2: ABC
    ,<string>Para3: zzz, <ref byte>Para4: 55'
  , Output-Parameter: '<byte> 0', ReturnValue: '<Int64> 0'"


Try looking in System.ServiceModel.OperationContext

I was able to get the current user within an IParameterInspector using System.ServiceModel.OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号