使用WCF REST服务上传文件
|
我是WCF和Rest服务的新手,并尝试从网上发现的帖子中进行一些实现,但仍然遇到一些问题。
因此,让我解释一下我的情况。
我有一个WPF应用程序,其中有一个反馈表,客户可以填写反馈表,附加一些屏幕截图并发送。现在,我的想法是将所有这些信息收集到一个我已经成功完成的XML文件中,然后将该XML文件上传到我服务器上的特定文件夹中。
现在,据我所知,客户端应用程序必须具有POST方法才能将流发布到服务器,然后我应该在服务器上有一个aspx页面来解码回从POST获得的流,并制定我的XML文件,然后将其保存在文件夹中,如果我输入错了,请纠正我。
目前,我已经在客户端上实现了以下代码:
public static void UploadFile()
{
serverPath = \"http://localhost:3402/GetResponse.aspx\";
filePath = \"C:\\\\Testing\\\\UploadFile\\\\UploadFile\\\\asd_asd_Feedback.xml\";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverPath);
//request.MediaType = \"text/xml\";
request.ContentType = \"text/xml\";
//request.Method = \"POST\";
request.Method = \"POST\";
//request.ContentLength = contentLength;
//request.ContentType = \"application/x-www-form-urlencoded\";
using (FileStream fileStream = File.OpenRead(filePath))
using (Stream requestStream = request.GetRequestStream())
{
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int byteCount = 0;
while ((byteCount = fileStream.Read(buffer, 0, bufferSize)) > 0)
{
requestStream.Write(buffer, 0, byteCount);
}
}
string result = String.Empty;
try
{
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
}
catch (Exception exc)
{
}
if (result == \"OK\")
{
}
else
{
// error...
}
}
现在如何将requestStream传递到GetResponse.aspx页?这是正确的方法吗?
感谢您的帮助和时间
没有找到相关结果
已邀请:
1 个回复
雇砰