Elastic fields due to single dislocations and dislocation pile-ups are computed in heterogeneous media like bi-materials, half-spaces and tri-materials thanks to the Leknitskii-Eshelby-Stroh formalism for two-dimensional anisotropic elasticity. The tri-material configuration allows to consider grain boundary regions with finite thickness and specific stiffness. The effects of these parameters are first studied in the case of a single dislocation in a Ni bicrystal. Image forces may arise because of both dissimilar grain orientations and the presence of a finite grain boundary region. In particular, it is shown that the Peach-Koehler force projected along the dislocation glide direction can exhibit a change of sign with the dislocation position. Therefore, an equilibrium position in the absence of applied stress can be found by coupling an attractive compliant grain boundary region with a repulsive orientation of the adjacent crystal, or a repulsive stiff grain boundary region with an attractive orientation. Regarding dislocation pile-ups, it is shown that the resolved shear stress scales approximately with the inverse of the square root distance from the leading dislocation in the pile-up. This scaling law remains valid in anisotropic elasticity for the chosen heterogeneous media. Both the grain boundary stiffness and grains misorientation influence pile-up length and resolved shear stress, but the effect of misorientation is clearly seen to be predominant. In the case where the leading dislocation is unlocked, the resolved shear stress at a given position in the neighboring grain is reduced when the grain boundary stiffness is increased due to the pushing back of dislocations from the grain boundary.