我有一个自托管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 !!!
对我来说有几个谜团:
非常感谢
答案 0 :(得分:0)
为什么这会将socket用于本地NamedPipe?
因为你在这里有UdpDiscoveryEndpoint
:
m_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
这里的不同电脑之间可以有什么变化?除了进程ID我没看到?