Rigging Robot arm Meganism

Hi all,

I am trying to rig a robot arm and there is something I can't figure out. 

What I try to make is the following: When the arm moves (with I.K. handel (armature A)) and the angle of B (Mesh) gets bigger or smaller, the part of A (mesh) moves up or down. I tried to realise this by using a transformation constraint; when  C (armature) rotates, B (armature) moves up or down. 

This looks to work until (armature) B moves up to much and it is not aligned with the upper arm any more. 

Does someone know how I can make a rig like this working?  [I added the Blender file to this forum-post; it seems like this didn't work].

I am also aware that the length of the piston is not correct. I will edit this later. 

Thanks!