【发布时间】:2013-10-02 14:01:39
【问题描述】:
我有一个自托管 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 !!!
对我来说有几个谜团:
- 为什么本地 NamedPipe 使用套接字?
- 在不同的计算机之间可以改变什么?除了我看不到的进程 ID?
- 我可以做些什么来进行更多调查?我有点迷路了。
非常感谢
【问题讨论】:
-
我不知道这是否是问题所在,但后缀为 process_id 的服务名称是 ..“对我来说很奇怪”。您的客户需要能够找到您的服务......并且此代码每次都会为您提供不同的服务名称。 "net.pipe://localhost/EmployeeService" , "net.pipe://localhost/ServiceName_EmployeeService" 这将是更常见的恕我直言。您的客户端如何连接到这个公开的服务(因为 process_id 波动)?
-
事实上:假设托管服务的应用程序是应用程序“A”。连接到该服务的应用程序是应用程序“B”。应用程序B其实就是启动应用程序“A”然后使用WCF服务配置应用程序A的很多参数的应用程序
-
好像有人取出了“SelfHost”的“Self”。我完全不明白那个动作。
-
这是一个问题和观察。为什么要在命名管道上设置安全性?什么可以在与本地机器对话的本地机器上截获该消息?
-
@granadaCoder :你完全正确,我看不出有任何正当理由在这里使用它。我将与创建者一起了解为什么要设置此安全性。
标签: c# .net wcf windows-xp named-pipes