publicObjectVersionCreateObject(inttype,PropertyValue[]propertyValues,Streamfile){// First upload the file.// Create the file upload request.stringuploadUrl="http://example.org/REST/files";varuploadRequest=WebRequest.Create(uploadUrl);uploadRequest.Method="POST";// Fill the authentication information.uploadRequest.Headers["X-Authentication"]=this.AuthenticationToken;// Upload the file.uploadRequest.ContentType="application/octet-stream";varuploadStream=uploadRequest.GetRequestStream();file.CopyTo(uploadStream);// Get the upload information from the response.// The information is in the response stream in JSON format.// DataContractJsonSerializer lets us deserialize it back into an object.varuploadResponse=uploadRequest.GetResponse();varuploadSerializer=newDataContractJsonSerializer(typeof(UploadInfo));varuploadInfo=(UploadInfo)uploadSerializer.ReadObject(uploadResponse.GetResponseStream());// Once the file is uploaded it can be used in object creation.// Construct the URL.// For object creation the URL only specifies the type.stringurl="http://example.org/REST/objects/"+type;varcreateRequest=WebRequest.Create(url);createRequest.Method="POST";createRequest.Headers["X-Authentication"]=this.AuthenticationToken;// Create the creation info.varcreationInfo=newObjectCreationInfo{PropertyValues=propertyValues,Files=new[]{uploadInfo}};// Send the creation info to the server.// Use JSON serializer to serialize it to the request stream.varinfoSerializer=newDataContractJsonSerializer(typeof(ObjectCreationInfo));infoSerializer.WriteObject(createRequest.GetRequestStream(),creationInfo);// Now get the response.varcreateResponse=createRequest.GetResponse();varserializer=newDataContractJsonSerializer(typeof(ObjectVersion));varobjectVersion=(ObjectVersion)serializer.ReadObject(createResponse.GetResponseStream());// Return the newly created object.returnobjectVersion;}