First off apologies: this post is >1yr old and responding to old posts is a bit off form.....but I have just spent 3 days fighting with the same problem so thought it worthwhile posting what I had to do.
I am using the latest managment SDK for 6.5.0 targetting .NET runtime 4.5.0.
I started with the sample code as given in the OVFManagerImportLocalVApp and found that it did upload the VMDK but that on inspection it contained no partitions &c.
So the things I had to change were:
- I explicitly set the Expect100Continue as "true" in the underlying service of the request. Not sure that this is anbsolutely required but the Java examples explicitly set it so I followed.
- I set the Content-Length header value with the size of the VMDK I was uploading.
- I had to set AllowWriteStreamBuffering to "false" as per https://support.microsoft.com/en-gb/help/908573/a-post-or-put-request-may-fail-when-you-use-the-httpwebrequest-class-t
- I only upload a 64K buffer at any given time.
- I renew the lease (porbably over often) in the upload loop
The final VMDK upload function that appears to work is:
void SendVMDKFile(Boolean put, string fileName, string url, long diskCapacity, ManagedObjectReference httpNfcLease) { byte[] buffer = new byte[(64*1024)+1]; Trace.TraceInformation("Destination host URL: " + url); Uri uri = new Uri(url); HttpWebRequest request = HttpWebRequest.CreateHttp(uri); NetworkCredential nwCred = new NetworkCredential(); long szVMDK = diskCapacity; if (0 == szVMDK) { System.IO.FileInfo fi = new System.IO.FileInfo(fileName); szVMDK = fi.Length; } request.ContentType = "application/x-vnd.vmware-streamVmdk"; request.ServicePoint.Expect100Continue = true; request.KeepAlive = true; request.Timeout = WebClientTimeout; request.AllowWriteStreamBuffering = false; request.ContentLength = szVMDK; if (put) { request.Method = "PUT"; } else { request.Method = "POST"; } System.IO.FileStream fileStream = new FileStream(fileName, FileMode.Open); Stream dataStream = request.GetRequestStream(); int len = 0; long totalWritten = 0; long threshold = 0; if (0 != szVMDK) { threshold = szVMDK / 20; } while ((len = fileStream.Read(buffer, 0, (64*1024))) > 0) { dataStream.Write(buffer, 0, len); dataStream.Flush(); totalWritten += len; if (0 != szVMDK) { _server.getConnection().Service.HttpNfcLeaseProgress(httpNfcLease, (int)(((double)(totalWritten / threshold)) * 5)); } Trace.TraceInformation("SendVMDKFile: Written {0} of {1} ({2:G}). Status {3}", totalWritten, szVMDK, ((double)(totalWritten / threshold)),fileStream.Position); } dataStream.Flush(); dataStream.Close(); fileStream.Close(); }
As mentioned, it hits the HttpNcfLeasedProgress a *lot* most of the other samples fire this off to a separate thread and update it significantly fewer times. But I have left it "as is".
So hopefully this is useful to someone else