Autor Beitrag
michihk
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Do 20.05.10 17:47 
Hallo erstmal.

Ich schicke per HTTP POST über FrontPageRPC teils riesige Dateien an einen Sharepointserver. Es klappt alles, außer dass ich alle Daten doppelt schicke: zuerst schreib ich sie in den RequestStream und wenn ich die Response anfordere werden alle Daten nochmal geschickt.

Ich bin schon ziemlich am verzweifeln. Ich hoff mir kann wer helfen.

Hier mal der relevante Code:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
string hosturl = "http://sharepoint";
string weburl = "/websites";
string fileurl = "Dokumente/test.pdf";
bool overwrite = true;
string title = "test";

string serviceName = hosturl + weburl + "/_vti_bin/_vti_aut/author.dll";


//RequestBody zusammenbasteln            
string method = "put document: 12.0.0.000";
string document = fileurl;
string metaInfo = string.Empty;
string putOption = overWrite ? "overwrite" : "edit";
string keepCheckedOutOption = "false";
string comment = string.Empty;
string returnStr = string.Empty;
byte[] data;
string returnError = string.Empty;

string fpRPCCallStr = "method={0}&service_name={1}&document=[document_name={2};meta_info=[{3}]]&put_option={4}&comment={5}&keep_checked_out={6}";

method = HttpUtility.UrlEncode(method);
putOption = HttpUtility.UrlEncode(putOption);
metaInfo = "vti_title;SW|" + title;
fpRPCCallStr = String.Format(fpRPCCallStr, method, serviceName, document, metaInfo, putOption, comment, keepCheckedOutOption);

//add line feed character to delimit end of command 
byte[] fpRPCCall = System.Text.Encoding.UTF8.GetBytes(fpRPCCallStr + "\n");

//webrequest "konfigurieren"
WebRequest wReq = WebRequest.Create(serviceName);
wReq.Credentials = nwc;
wReq.Method = "POST";
wReq.Proxy = GetDefaultProxy(nwc);
wReq.ContentType = "application/x-vermeer-urlencoded";
wReq.Headers.Add("X-Vermeer-Content-Type""application/x-vermeer-urlencoded");
wReq.Timeout = Timeout.Infinite;
wReq.ContentLength = fpRPCCall.Length + fileBinary.Length;

Stream requestStream = wReq.GetRequestStream();

//den fp RPC call abstezen
requestStream.WriteTimeout = System.Threading.Timeout.Infinite;
requestStream.Write(fpRPCCall, 0, fpRPCCall.Length);

requestStream.Flush();

// buffer definieren
int bytesRead = 0;
int chunkSize = 4096;
int tailSize;
int chunkNum = Math.DivRem((int)fileBinary.Length, chunkSize, out tailSize);


int sleep = 10;

// daten hochschieben
for (int j = 0; j < chunkNum; j++)
{
  data = new byte[chunkSize];
  bytesRead = fileBinary.Read(data, 0, chunkSize);

  requestStream.Write(data, 0, chunkSize);
  requestStream.Flush();
  if(((j+1)*chunkSize%(1024*1024))==0)
    Console.WriteLine((j + 1) * chunkSize / 1024 + "kB");
  Thread.Sleep(sleep);
}

//send the remainde if any. 
if (tailSize > 0)
{
  data = new byte[tailSize];
  bytesRead = fileBinary.Read(data, 0, tailSize);
  
  requestStream.Write(data, 0, tailSize);
  requestStream.Flush();
}

requestStream.Flush();
requestStream.Close();
requestStream.Dispose();

//Response anfordern - jetzt schickt er nochmal alle daten mit, d.h. ein 20 mb file erzeugt 40 mb traffic
WebResponse response = wReq.GetResponse();


lg