The magnetic field of the solar wind near the Sun is very difficult to measure directly. Measurements of Faraday rotation of linearly polarized radio sources occulted by the solar wind provide a unique opportunity to estimate this magnetic field, and the technique has been widely used in the past. However, Faraday rotation is a path integral of the product of electron density and the projection of the magnetic field on the path. The electron density near the Sun can be measured by several methods, but it is quite variable. Here we show that it is possible to measure the path-integrated electron density and the Faraday rotation simultaneously at 6–10 R⊙ using millisecond pulsars as the linearly polarized radio source. By analysing the Faraday rotation measurements with and without the simultaneous electron density observations, we show that these observations significantly improve the accuracy of the magnetic field estimates.