Heat oven to 350ºF. Grease a 2-quart baking dish with butter.
Use a sharp knife to cut corn kernels from cobs. Reserve 4 stripped cobs and break in half (discard others).
Add milk and cream to a medium saucepan set over medium heat and add reserved cobs. Bring to a simmer and cook 20 minutes. Remove from heat.
Meanwhile, melt butter in a large skillet over medium heat. Add shallots and cook, stirring occasionally, until softened and translucent, 2 to 3 minutes. Add corn kernels and cook until just softened, about 5 minutes.
Remove corncobs from milk-cream mixture and discard. Transfer mixture to a large bowl, then add sautéed shallots and corn kernels. Add flour, sugar, and salt and stir to combine. If mixture is still steaming, let it cool for about 10 minutes. Transfer all but 2 cups of the mixture to a blender. Blend until smooth. Return blended mixture to the bowl with the remaining corn mixture. Add eggs and cheese and stir to combine. Transfer to prepared baking dish. Bake until golden and puffed, 35 to 40 minutes. Serve warm.