Doflamingo Obviously must have stronger Haki, as seen even Luffy's G2 attacks werent working on him... and as it was mentioned by smoker, strong Haki is needed to withstand Law's attacks, so yeah again I think is very likely that being on guard and protecting himself makes the difference
otherwise Law should've always Teleported Doflamingo and hit him point blank with every attack