title: Apache Thrift Client Run time issues in c#
body: <p>I am working on a client - server application written in C# that is built using the Apache THRIFT RPC framework. </p>
  
  <p>We have created several IDL files (.thrift files) with service definitions. These services have been implemented in the server and are being called from the client. </p>
  
  <p>An example of a struct and a service definition in an IDL file is given below</p>
  
  <p>struct ViewColumn {</p>
  
  <pre><code>1: string ColumnProperty,
  2: i32 ColWidth,
  3: i32 ColPosition,
  4: bool ColAscending,
  5: i32 ColSortOrder,
  </code></pre>
  
  <p>}</p>
  
  <p>struct FormView {</p>
  
  <pre><code>   1: i32 ID
     2: string formname
     3: list&lt;ViewColumn&gt; SelectedColumns
  </code></pre>
  
  <p>}</p>
  
  <p>service  FormQueries {</p>
  
  <pre><code>   1: FormView FetchFormView()
  </code></pre>
  
  <p>}</p>
  
  <p>There are a number of such services defined in the entire application.</p>
  
  <p>In the server the service has been implemented as follows</p>
  
  <pre><code>    Public FormView FetchFormView() {
  
    return something
  
  }
  </code></pre>
  
  <p>The configuration of the client and server is as follows</p>
  
  <p>Client
  1. TSocket
  2  TBinaryprotocol
  3. TMultiplexedProtocol</p>
  
  <p>Server
  1. TserverSocket
  2. Tmultiplexedprocessor
  3. TbinaryProtocol</p>
  
  <p>Upon calling the service from the client as follows </p>
  
  <p><code>var f = Queries.FetchFormView()</code></p>
  
  <p>we encountered some problems. </p>
  
  <ol>
  <li>FetchFormView() returns null</li>
  <li>system.OutOfMemoryException</li>
  </ol>
  
  <p>The stack trace of these errors are provided below</p>
  
  <pre><code>Exception of type 'System.OutOfMemoryException' was thrown.
     at Thrift.Protocol.TBinaryProtocol.ReadStringBody(Int32 size) 
     at Thrift.Protocol.TBinaryProtocol.ReadMessageBegin() 
     at Thrift.Protocol.TProtocolDecorator.ReadMessageBegin() 
     at Queries.recv_FetchFormView()
     at System.Windows.Forms.Control.OnClick(EventArgs e)
     at System.Windows.Forms.Button.OnClick(EventArgs e)
     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
     at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
     at System.Windows.Forms.Control.WndProc(Message&amp; m)
     at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
     at System.Windows.Forms.Button.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  
  FetchFormView failed: unknown result (result is null)
  NOTE: This error occurs with other defined services also
     at Queries.recv_FetchFormView()
     at Queries.Client.FetchFormView()
     at Queries.FetchFormView()
     at System.Windows.Forms.ToolStripDropDownItem.OnDropDownShow(EventArgs e)
     at System.Windows.Forms.ToolStripMenuItem.OnDropDownShow(EventArgs e)
     at System.Windows.Forms.ToolStripDropDownItem.ShowDropDownInternal()
     at System.Windows.Forms.ToolStripDropDownItem.ShowDropDown(Boolean mousePush)
     at System.Windows.Forms.ToolStripMenuItem.OnMouseButtonStateChange(MouseEventArgs e, Boolean isMouseDown)
     at System.Windows.Forms.ToolStripMenuItem.OnMouseDown(MouseEventArgs e)
     at System.Windows.Forms.ToolStripItem.HandleMouseDown(MouseEventArgs e)
     at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
     at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
     at System.Windows.Forms.ToolStrip.OnMouseDown(MouseEventArgs mea)
     at System.Windows.Forms.Control.WmMouseDown(Message&amp; m, MouseButtons button, Int32 clicks)
     at System.Windows.Forms.Control.WndProc(Message&amp; m)
     at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
     at System.Windows.Forms.ToolStrip.WndProc(Message&amp; m)
     at System.Windows.Forms.MenuStrip.WndProc(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  </code></pre>
  
  <p>If you have experience in using Apache THRIFT in enterprise level applications, please provide me with insights / solutions / ideas and best approaches.</p>
  
  <p>This is a critical situation. Any help is appreciated.</p>
  
  <p>Thanks a ton in advance</p>
  
  <p>Romi</p>
  
  <p><strong>UPDATE - 26/7/13</strong></p>
  
  <p>I have improvised a solution. I am closing /disposing off and recreating the transport and protocol objects before every service call. This is an inefficient way of connecting with the server but it is working. I am thinking of making each service call asynchronous. Probably that will be a better solution.</p>