有人知道如何设置发现的超时时间吗?默认值似乎为10-15秒,这有点长...
是在哪一侧进行配置?服务端还是客户端?
服务端:
// Add a ServiceDiscoveryBehavior
host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
// Add a UdpDiscoveryEndpoint
host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
客户端:
EndpointAddress endPoint = null;
endPoint = FindCalculatorServiceAddress();
static EndpointAddress FindCalculatorServiceAddress()
{
// Create DiscoveryClient
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
// Find IStringReverser endpoints
FindResponse findResponse = discoveryClient.Find(new FindCriteria(typeof(IStringReverser)));
if (findResponse.Endpoints.Count > 0)
{
return findResponse.Endpoints[0].Address;
}
else
{
return null;
}
}
提前感谢您。
FindAsync()
方法与FindProgressChanged
和FindCompleted
事件而不是同步的Find()
方法,那么FindProgressChanged
事件会在端点结果出现时立即触发,这意味着你将立即访问它们,而不必等待搜索结束。如果你对更多的结果不感兴趣,你可以选择执行CancelAsync()
,或者让它运行直到超时,此时FindCompleted
会被触发。 - Alex