0

我有一个自托管 WCF 服务的应用程序(以允许另一个应用程序试运行该应用程序)。

该服务在我们所有的测试计算机(Windows 7、Windows XP)上运行良好,但我们的一位客户(在 windows xp 上)只是打电话给我们,在发布时报告了一个异常。

通过我们的软件跟踪,我们发现了以下内容:

似乎当我们进行ServiceHost.Open调用时,我们得到了这个异常:

System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.ServiceModel.Channels.UdpUtility.BindSocket(Socket socket, IPEndPoint localEndpoint)
   at System.ServiceModel.Channels.UdpUtility.CreateListenSocket(IPAddress ipAddress, Int32& port, Int32 receiveBufferSize, Int32 timeToLive, Int32 interfaceIndex, Boolean allowMulticastLoopback, Boolean isLoopbackAdapter)
   at System.ServiceModel.Channels.UdpChannelListener.InitSockets(Boolean updateListenPort)
   at System.ServiceModel.Channels.UdpChannelListener..ctor(IUdpTransportSettings settings, BindingContext context)
   at System.ServiceModel.Channels.UdpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
   at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()
   at System.ServiceModel.Channels.MessageEncodingBindingElement.InternalBuildChannelListener[TChannel](BindingContext context)
   at System.ServiceModel.Channels.TextMessageEncodingBindingElement.BuildChannelListener[TChannel](BindingContext context)
   at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[TChannel]()
   at System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
   at System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession)
   at System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnBeginOpen()
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

我看了一点这个错误,似乎它可能与提供的错误 IP 有关。

首先,这是我们创建服务的方式:

m_host = new ServiceHost(m_ourServiceInstance);
NetNamedPipeBinding namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
namedPipeBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
SetBindingDefaultTimeouts(namedPipeBinding);
String url = String.Format("net.pipe://localhost/ServiceName_{0}", Process.GetCurrentProcess().Id);
m_host.AddServiceEndpoint(typeof(IOurServiceType), namedPipeBinding, url);
m_host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
m_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
m_host.Open();//Crash on this line !!!

对我来说有几个谜团:

  1. 为什么这对本地 NamedPipe 使用套接字?
  2. 这里的不同计算机之间可以改变什么?除了我看不到的进程ID?
  3. 我能做些什么来调查更多?我在这里有点迷路了。

非常感谢

4

1 回答 1

0

为什么这对本地 NamedPipe 使用套接字?

因为你在UdpDiscoveryEndpoint这里:

m_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

这里的不同计算机之间可以改变什么?除了我看不到的进程ID?

  1. 试图以访问权限禁止的方式访问套接字。
  2. 您已经拥有相同的合格地址(可能来自未正确处理它的非托管资源的先前进程。或尚未关闭)以获取更多信息:MSDN
于 2013-10-02T15:55:01.113 回答