Hallo, ich versuche XML-Dateien aus einem Ordner mit Webservice in einen anderen Ordner auf meinem lokalen Computer zu senden, Dateien erfolgreich gesendet werden und die Anwendung wird normal geschlossen, aber das Problem ist, dass Dateien für immer in geändert wird der Zielordner und wenn ich versuche, den Webservice erneut anzurufen gibt es eine Ausnahmezeit. hier ist mein CodeSenden von Dateien mit Httpwebrequest
public void SendC_XML(string path, string queueID, string application, string servicewTMURI)
{
HttpWebRequest httpWebRequest2 = null;
//Stream memStream = null;
//FileStream fileStream = null;
String[] listOfFiles = Directory.GetFiles(path, "*.xml");
for (int i = 0; i < listOfFiles.Length; i++)
{
try
{
MyLog.Add("found path " + listOfFiles[i]);
string[] ImagesArray = listOfFiles[i].Split('\\');
string ImageName = ImagesArray[ImagesArray.Length - 1];
int index = ImageName.IndexOf(".");
if (index > 0)
ImageName = ImageName.Substring(0, index);
MyLog.Add("image name = " + ImageName);
string[] textArray1 = new string[] { servicewTMURI, "/Queue/SetFile/", application, "/", queueID, "/" + ImageName + "/xml" };
string requestUriString = string.Concat(textArray1);
Guid guid = new Guid();
string boundary = "---------------------------" + guid;
httpWebRequest2 = (HttpWebRequest)WebRequest.Create(requestUriString);
httpWebRequest2.ContentType = "multipart/form-data; boundary=" +
boundary;
MyLog.Add("ContentType = " + httpWebRequest2.ContentType);
httpWebRequest2.Method = "POST";
httpWebRequest2.KeepAlive = false;
httpWebRequest2.Timeout = 5000;
httpWebRequest2.Proxy = null;
httpWebRequest2.ServicePoint.ConnectionLeaseTimeout = 5000;
httpWebRequest2.ServicePoint.MaxIdleTime = 5000;
httpWebRequest2.Credentials =
System.Net.CredentialCache.DefaultCredentials;
using (Stream memStream = new System.IO.MemoryStream())
{
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
boundary + "\r\n");
string formdataTemplate = "\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
memStream.Write(boundarybytes, 0, boundarybytes.Length);
string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n";
//for (int i = 0; i < files.Length; i++)
//{
//MyLog.Add("file = " + files[i]);
string header = string.Format(headerTemplate, "uplTheFile", listOfFiles[i]);
byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
memStream.Write(headerbytes, 0, headerbytes.Length);
using (FileStream fileStream = new FileStream(listOfFiles[i], FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
memStream.Write(buffer, 0, bytesRead);
}
memStream.Write(boundarybytes, 0, boundarybytes.Length);
fileStream.Close();
}
httpWebRequest2.ContentLength = memStream.Length;
using (Stream requestStream = httpWebRequest2.GetRequestStream())
{
memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
requestStream.Close();
}
//httpWebRequest2.Abort();
httpWebRequest2 = null;
//webResponse2 = null;
}
}
catch (Exception ex)
{
MyLog.Add("error in cXML method = " + ex.Message);
}
finally
{
//memStream.Close();
//fileStream.Close();
//requestStream.Close();
try
{
if (httpWebRequest2 != null)
{
MyLog.Add("heeeeeeeeeeeeeeey request != null");
httpWebRequest2.GetRequestStream().Close();
httpWebRequest2 = null;
}
}
catch (Exception exception2)
{
throw exception2;
}
}
}
}
aber die Dateien sind leer im Zielordner :( – user1814595
Was ist der Dateityp? Ist es ein Bild zum Beispiel –
die Datei.xml :) – user1814595