Silverlight 中的 WCF 重新连接
本文关键字:重新连接 WCF 中的 Silverlight | 更新日期: 2023-09-27 18:30:29
我正在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()
有谁知道问题的根源是什么以及如何解决?
我使用了服务器的DNS名称。因此,当我下次连接时,WCF 核心正在尝试解析 dns 名称,如果 dns 不可用,wcf 核心会抛出套接字异常:
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 核心将失败,如问题中所述。
使用 IP 地址(不是 dns 名称)进行 tcp 绑定