【发布时间】:2021-11-01 05:35:02
【问题描述】:
除了从 EndpointDispatcher 访问 ClientRuntime 之外,还有其他方法吗?
似乎在 .NET 5.0 中,使用 System.ServiceModel 4.8.1,EndpointDispatcher 类是完全空的,只包含一个空构造函数。
我们曾经进行过一些测试来检查 IEndpointBehavior 是否已使用 WCF 正确添加到客户端。
var myEndpointBehavior = new MyEndpointBehavior();
var serviceEndpoint = new ServiceEndpoint(new ContractDescription("localhost"));
var dispatcher = new EndpointDispatcher(new EndpointAddress("http://localhost"), "", ""); // <--- Error because EndpointDispatcher class is totally empty
var clientRuntime = dispatcher.DispatchRuntime.CallbackClientRuntime; // <---- does not exist
clientRuntime.ClientMessageInspectors.Should().HaveCount(0);
myEndpointBehavior.ApplyClientBehavior(serviceEndpoint, clientRuntime);
clientRuntime.ClientMessageInspectors.Should().HaveCount(1);
clientRuntime.ClientMessageInspectors.First().Should().BeOfType<MyEndpointBehaviorMessageInspector>();
有没有办法在 .NET 5.0 中测试同样的行为?
【问题讨论】:
-
您发送的链接都是针对 .NET Framework 的,正如我上面提到的,这曾经在 .NET Framework 中正常工作,但在 .NET Core 和 .NET5.0 中完全改变了。所以这些资源不再适用