Tutorial :How to returnlarge and complex objects from a WCF Serice?



Question:

i think i have a serialization or a sizing problem when trying to return a complex object (an object with nested objects with nested objects..).

The error code i get a CommunicationException. Any idea?

EDIT : This is the stacktrace

A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll  System.ServiceModel.CommunicationException: Connessione sottostante chiusa: Chiusura imprevista della connessione.. ---> System.Net.WebException: Connessione sottostante chiusa: Chiusura imprevista della connessione..     in System.Net.HttpWebRequest.GetResponse()     in System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)     --- Fine dell'analisi dello stack dell'eccezione interna ---    Server stack trace:      in System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)     in System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)     in System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)     in System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)     in System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)     in System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)     in System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)     in System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)     in System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     in System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)     in System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)     in System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:      in System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)     in System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)     in RecuperoPagati.DataCoreReference.IDataCoreService.GetDossierByNumDossier(String Env, String NumDossier)     in RecuperoPagati.DataCoreReference.DataCoreServiceClient.GetDossierByNumDossier(String Env, String NumDossier) in C:\Documents and Settings\gdipietro\Documenti\Dev\Rifatturazione\RecuperoPagati\RecuperoPagati\RecuperoPagati\Service References\DataCoreReference\Reference.vb:riga 198     in RecuperoPagati.WebUserControl1.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\gdipietro\Documenti\Dev\Rifatturazione\RecuperoPagati\RecuperoPagati\RecuperoPagati\WebUserControl1.ascx.vb:riga 8  


Solution:1

I agree with John; it's probably not a type complexity issue. To smoke out the real culprit, you can try adding diagnostic logging to your service configuration. WCF's tracing and logging features are very powerful and can help you find the root cause of most issues.

If you're running VS2008, you should see a menu option for "Edit WCF Configuration" when you right click the config file of your service host project. Select the "Diagnostics" node to enable tracing and message logging.

http://msdn.microsoft.com/en-us/library/ms730064.aspx

The output from this log can be viewed quite effectively in the Service Trace Viewer Tool, which should already be on your machine (comes with the framework).

http://msdn.microsoft.com/en-us/library/ms732023.aspx


Solution:2

The problem probably has nothing to do with the complexity of the type. Please post the complete exception, with all InnerException's. Just catch the exception and post ex.ToString().


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »