WCF DiscoverClient.FindAsync抛出SocketException

问题描述 投票:0回答:1

我们有WCF服务

var address = string.Format("net.tcp://{0}", _settings.ServerAddress);
var binding = new NetTcpBinding(SecurityMode.None) { HostNameComparisonMode = HostNameComparisonMode.Exact };

var service = new LicenseService();

_host = new ServiceHost(service);
_host.AddServiceEndpoint(typeof(ILicenseService), binding, address);
_host.AddServiceEndpoint(typeof(ILicenseServiceAdmin), binding, address);
_host.Description.Behaviors.Add(behavior);
_host.Description.Behaviors.Add(throottling);

_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
_host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());

_host.Open();

和客户

var searchCriteria = new FindCriteria(typeof(Utils.Licensing.ILicenseService));
_discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
_discoveryClient.FindProgressChanged += Client_FindProgressChanged;
_discoveryClient.FindCompleted += Client_FindCompleted;
_discoveryClient.FindAsync(searchCriteria, _syncObject);

它对我们所有的客户都很好,除了最近报告以下错误的一个客户:

System.Net.Sockets.SocketException(0x80004005):Einungültiges参数wurde angegeben在System.Net.Sockets.Socket..ctor(AddressFamily addressFamily,SocketType socketType,ProtocolType protocolType)在System.ServiceModel.Channels.UdpUtility.CreateListenSocket(IPAddress ipAddress,Int32&端口,Int32 receiveBufferSize,Int32 timeToLive,Int32 interfaceIndex,布尔allowMulticastLoopback,布尔isLoopbackAdapter)在System.ServiceModel.Channels.UdpChannelFactory'1.GetSockets(Uri通过,IPEndPoint&remoteEndPoint,Boolean&isMulticast)在System.ServiceModel.Channels.UdpChannelFactory'1.OnCreateChannel(EndpointAddress to,Uri via)在System.ServiceModel.Channels.ChannelFactoryBase'1.InternalCreateChannel(EndpointAddress地址,Uri通过)在System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverDuplex.CreateInnerChannelBinder(EndpointAddress to,Uri via)在System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress地址,Uri通过)在System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(类型channelType,EndpointAddress地址,Uri通过)在System.ServiceModel.DuplexChannelFactory'1.CreateChannel(InstanceContext callbackInstance,EndpointAddress地址,Uri通过)在System.ServiceModel.ClientBase'1.CreateChannel()在System.ServiceModel.ClientBase'1.CreateChannelInternal()在System.ServiceModel.ClientBase'1.get_Channel()在System.ServiceModel.ClientBase'1.get_InnerChannel()在System.ServiceModel.Discovery.DiscoveryClient.FindAsync(FindCriteria条件,对象userState)

将所有必需的规则添加到防火墙。我们也尝试使用规则,但是代码找不到服务或找不到服务。它永远不会引发异常。

我们无法物理访问客户的计算机,而我们的主要困难是重现此错误。

非常感谢您的帮助。

EDIT 2019-10-22

事实证明,客户从共享文件夹中运行WCF客户端。由于安全设置,套接字连接失败。目前尚不清楚哪个设置在这里起作用,但是,在本地复制WCF客户端后,问题就消失了。

c# sockets wcf udp
1个回答
1
投票

您的代码没有问题,我对其进行了测试,发现客户端代码可以正确找到服务地址。这可能是客户端的配置问题。例如,服务器和客户端共享的服务合同是否一致,搜索条件参数是否一致?此外,客户端报告的错误似乎是非英语的“指定无效参数”?您能给我错误消息的英文版吗?我还没有遇到类似的问题,但这全都是关于客户端而不是服务器端的。请随时告诉我是否有什么我可以帮助的。

© www.soinside.com 2019 - 2024. All rights reserved.