Question

I've an application that self-host a WCF service(to allow another application to pilot the application).

The service was working fine on all our tests computers(Windows 7, Windows XP), but one of our customer(on windows xp) just called us reporting an exception at the launch.

With our software trace we found the following:

It seems that when we do the ServiceHost.Open call, we get this exception:

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)

I looked a little bit on this error, and it seems it can be related to a wrong IP provided.

First, here is how we create our service:

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 !!!

Several mysteries for me:

  1. Why does this use socket for local NamedPipe?
  2. What can change between different computers here? Except the process id I don't see?
  3. What can I do to investigate more ? I'm a little lost here.

Thank you very much

Was it helpful?

Solution

Why does this use socket for local NamedPipe?

Because you have UdpDiscoveryEndpoint here:

m_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

What can change between different computers here? Except the process id I don't see?

  1. An attempt was made to access a socket in a way forbidden by its access permissions.
  2. you have already the same qualified address (maybe from previous process that not disposed properly it's unmanaged resources . or not shutdown yet) for more info: MSDN
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top