2012-04-08 87 views
1

我在Silverlight中實現WCF服務代理(NetTcpBinding)的重新連接機制。服務的操作被計時器並行地調用。實現方法非常簡單(like here),但表格時,我的應用程序failes有例外:Silverlight中WCF重新連接

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()  

有誰知道什麼是問題的根源,以及如何解決呢?

+0

你能告訴你的源?看起來像一個簡單的空引用異常,可能是您的代碼中的問題。 – gideon 2012-04-09 04:22:43

+0

請看一下答案。 – 2012-04-14 11:26:36

回答

1

我已經使用了服務器的DNS名稱。其結果是,當我連接下一次,WCF核心試圖解析DNS名稱,如果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會按照問題中所描述的方式失敗。對於TCP結合

使用IP ADRESS(不DNS名稱)