http文件上载到wcf rest服务时出现问题
我想使用如下表单上传文件:http文件上载到wcf rest服务时出现问题,wcf,file,rest,file-upload,Wcf,File,Rest,File Upload,我想使用如下表单上传文件: <form action="http://127.0.0.1:8090/MyService/" method="post" enctype="multipart/form-data"> <p>Select File<br> <input name="Datei" type="file" size="50"> <input type="submit" value="Submit"
<form action="http://127.0.0.1:8090/MyService/"
method="post" enctype="multipart/form-data">
<p>Select File<br>
<input name="Datei" type="file" size="50">
<input type="submit" value="Submit">
</p>
</form>
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/", Method = "POST")]
void UploadFile(Stream fileContents);
}
ÿØÿà...
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/{filename}", Method = "POST")]
void UploadFile(string filename, Stream fileContents);
}
我有两个问题。当我将流写回文件时,它不仅包含文件数据,还包含一些http内容。这似乎很奇怪。是否有很好的方法获取原始文件数据
-----------------------------67832811011758
Content-Disposition: form-data; name="Datei"; filename="haha.jpg"
Content-Type: image/jpeg
ÿØÿà...
原始文件如下所示:
<form action="http://127.0.0.1:8090/MyService/"
method="post" enctype="multipart/form-data">
<p>Select File<br>
<input name="Datei" type="file" size="50">
<input type="submit" value="Submit">
</p>
</form>
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/", Method = "POST")]
void UploadFile(Stream fileContents);
}
ÿØÿà...
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/{filename}", Method = "POST")]
void UploadFile(string filename, Stream fileContents);
}
其次,我想在wcf的文件名。理想情况如下:
<form action="http://127.0.0.1:8090/MyService/"
method="post" enctype="multipart/form-data">
<p>Select File<br>
<input name="Datei" type="file" size="50">
<input type="submit" value="Submit">
</p>
</form>
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/", Method = "POST")]
void UploadFile(Stream fileContents);
}
ÿØÿà...
[ServiceContract]
public interface IDocumentConverter
{
[OperationContract, WebInvoke(UriTemplate = "/{filename}", Method = "POST")]
void UploadFile(string filename, Stream fileContents);
}
但这不起作用,因为我不知道如何使用表单/输入内容将文件名集成到url中。我已经编辑了您的标题。请参阅“”,其中的共识是“不,他们不应该”。