文档介绍:WCF REST方式上传文件
C#服务端
//------------
using ;
using ;
[ServiceContract]
public partial interface IOfficeServiceQ
{
[OperationContract] //rest下不是必须的,上传使用post,webInvoke方式
[WebInvoke(UriTemplate = "uploadimage/{comment}", Method = "POST", RequestFormat = )]//
[Description("上传图片测试")]
int uploadimage(Stream pic, ment);
}
//
[ServiceBehavior(InstanceContextMode = , Namespace = "", ConcurrencyMode = )]
public class ServiceOfficeQ : IOfficeServiceQ
{
public int uploadimage(Stream pic, ment)
{
/*有头信息时使用,做一些辅助信息之类的
WebHeaderCollection headerCollection = ;
foreach (string item in headerCollection)
{
string value = (item);
("headerz;"+value);
}
*/
//下面的代码支持,客户端直接上传图片流或者带表单的文件,带表单的文件的好处是你可以从里面得到名字和类型这里的例子就以jpg类型为例子
using(var ms=new MemoryStream())
{
(ms);
=0;//
Encoding encoding=;
var reader=new StreamReader(ms,encoding);
var headerLength=0;
----------------------8cc0b8cfcfd5ed2
Content-Disposition: form-data; name="file"; filename=""
Content-Type: application/octet-stream
这里是真正的文件内容
-----------------------8cc0