Sorry I took so long, had to dig this up, but this is what I use to write a XML file from a memory stream. I use this for 2 purposes, One to transmit to the rate server, and Two to write to the drive for troubleshooting a bad rate.
I was thinking that you wrote the file, but the writer did not have any data to write, so you wrote an empty XML file. You can test that theory by looking at the XML data before you write it to the disk drive.
Dim request As RateService_V12.RateRequest = New RateService_V12.RateRequest()
request.value = "such and such"
Dim response_serializer As XmlSerializer = Nothing
response_serializer = New XmlSerializer(GetType(RateService_V12.RateReply))
Dim request_writer As StreamWriter = Nothing
request_writer = New StreamWriter(HttpContext.Current.Server.MapPath("~\App_Data\Shipping\Logs\FEDEX\RateRequest_" & Order_Number & ".xml"))
request_serializer.Serialize(request_writer, request)
If Not (request_writer Is Nothing) Then request_writer.Close()