gpt4 book ai didi

c# - IDIspatchMessageInspector

转载 作者:可可西里 更新时间:2023-11-01 08:19:28 38 4
gpt4 key购买 nike

我实现 IDispatchMessageInspector.AfterReciveRequest然后我这样配置:

<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="inspectorBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>

</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="inspectorBehavior">
<serviceInspectors />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add
name="serviceInspectors"
type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>

但它不起作用。

我检查了我的程序集和本地引用,但没有找到 Microsoft.WCF.Documentation.InspectorInserterHostApplication dll我在网上搜索下载 HostApplication dll,但我一无所获。

我需要做什么?

我需要实现更多的东西或者我只需要这个配置。

最佳答案

我发现使用同样扩展属性的 IServiceBehavior 实现来附加我的 IDispatchMessageInspector 实现要容易得多。然后在 ApplyDispatchBehavior 方法中,将消息检查器附加到所有 channel 中的所有端点。

article对我帮助很大。

示例代码:

public class MyServiceBehavior : Attribute, IServiceBehavior
{
public void ApplyDispatchBehavior( ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase )
{
foreach( ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers )
foreach( EndpointDispatcher eDispatcher in cDispatcher.Endpoints )
eDispatcher.DispatchRuntime.MessageInspectors.Add( new RequestAuthChecker() );
}
}

然后在您的服务契约的实现中,您只需将属性添加到类中即可。

[ServiceBehavior( InstanceContextMode = InstanceContextMode.PerCall )]
[MyServiceBehavior]
public class ContractImplementation : IServiceContract
{

关于c# - IDIspatchMessageInspector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3523833/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com