1

我正在Silverlight中实现 WCF 服务代理 (NetTcpBinding) 的重新连接机制。服务的操作由计时器并行调用。实现非常简单(就像这里),但是我的应用程序失败时出现异常:

Uncaught Error: Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(Exception exception, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.Socket.DoResolve(DnsEndPoint dnsep, SocketAsyncEventArgs usersArgs)
at System.Net.Sockets.Socket.StaticResolveCallback(Object args)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()     

有谁知道问题的根源是什么以及如何解决?

4

1 回答 1

1

我使用了服务器的 dns 名称。结果,当我下次连接时,WCF 核心正在尝试解析 dns-name,如果 dns 不可用,wcf 核心会抛出 SocketException:

    System.Net.dll!System.Net.Dns.GetAddrInfo(string name = "myhost.com") + 0x200 bytes 
    System.Net.dll!System.Net.Dns.InternalGetHostByName(string hostName, bool includeIPv6) + 0x90 bytes 
    System.Net.dll!System.Net.Sockets.Socket.DoResolve(System.Net.DnsEndPoint dnsep, System.Net.Sockets.SocketAsyncEventArgs usersArgs = {System.Net.Sockets.SocketAsyncEventArgs}) + 0x72 bytes    
    System.Net.dll!System.Net.Sockets.Socket.StaticResolveCallback(object args) + 0x6f bytes    
    mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3d bytes 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0x97 bytes    
    mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5b bytes 
    mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x199 bytes  
    mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes 

并且 wcf 核心变为无效状态。当调用某些操作时,wcf-core 会失败,如问题中所述。

使用 ip 地址(不是 dns 名称)进行 tcp 绑定

于 2012-04-14T10:43:35.023 回答