我的应用程序使用第三方SOAP app服务。如何使用Audit.Net记录我的应用程序( SOAP客户端)发出的所有请求/响应?类似于Audit.HttpClient扩展。
问候
发布于 2021-07-17 04:01:12
一种选择是使用Audit.DynamicProxy拦截代理调用,例如,如果使用ChannelFactory创建代理,则可以执行以下操作:
using Audit.DynamicProxy;
public T CreateProxy<T>(Uri uri, HttpBindingBase binding)
{
var channelFactory = new ChannelFactory<T>(binding, new EndpointAddress(uri));
return AuditProxy.Create<T>(channelFactory.CreateChannel());
}然后,当您进行服务呼叫时,例如:
var proxy = CreateProxy<ICatalogService>(uri, binding);
var product = proxy.GetDetailedProductInfo(new GetDetailedProductInfoRequest() { ProductId = "1234" };您应该会得到一个审计事件,其格式类似于:
{
"EventType": "generatedProxy_1.GetDetailedProductInfo",
"Environment": {
...
},
"StartDate": "2021-07-16T19:48:15.294298Z",
"EndDate": "2021-07-16T19:48:21.6566853Z",
"Duration": 6362,
"InterceptEvent": {
"ClassName": "generatedProxy_1",
"MethodName": "GetDetailedProductInfo",
"IsAsync": false,
"InstanceQualifiedName": "generatedProxy_1, ProxyBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"MethodSignature": "CatalogService.GetDetailedProductInfoResponse GetDetailedProductInfo(CatalogService.GetDetailedProductInfoRequest)",
"Arguments": [
{
"Index": 0,
"Type": "GetDetailedProductInfoRequest",
"Value": {
"request": {
"ProductId": "1234"
}
}
}
],
"Success": true,
"Result": {
"Type": "GetDetailedProductInfoResponse",
"Value": {
"GetDetailedProductInfoResult": {
"Product": {
"ProductId": "1234",
"Description": "Some description".
"CreationDate": "2007-10-31T11:30:35-06:00"
}
}
}
}
}
}发布于 2021-07-30 16:58:16
https://stackoverflow.com/questions/68407920
复制相似问题