Electromagnet with a pipe as the core
You had to use a non-magnetic pipe. Plastic. Copper. Aluminium. Amagnetic steel. Anything but iron, nickel, cobalt.
Iron is used for magnetic cores because it presents least magnetic resistance to the magnetic field. So the magnetic flux runs almost completely through the iron and not through its surroundings. But that's exactly that what you want. Running the flux through the surroundings of the iron.