将复杂类型传递给WCF Rest服务,将stream作为另一个参数

时间:2013-10-13 04:40:05

标签: wcf rest

我正在尝试使用visual studio 2012和.net framework 4.5创建一个wcf rest服务。该服务将尝试将文件与4个或更多参数一起上传。我想只在一个电话中这样做。我想使用http“put”方法。但我一直有这两个错误。

  

合同'IRestBasketService'中的'AddFile'操作有多个请求体参数,其中一个是Stream。当Stream是一个参数时,正文中不能有其他参数。

(当我使用BodyStyle包裹时)

  

合同'IRestBasketService'的操作'AddFile'指定要序列化的多个请求体参数,而不包含任何包装元素。最多可以在没有包装元素的情况下序列化一个body参数。删除额外的body参数或将WebGetAttribute / WebInvokeAttribute上的BodyStyle属性设置为Wrapped。

(当我使用BodyStyle时)

我该怎么办?

以下是给我错误的2个签名

[WebInvoke(Method = "PUT",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "AddFile?key={key}&email={email}&fileName={fileName}&groupID={groupID}&ID=   {objectID}")]
Response AddFile(string key, string email, string fileName, string type, string objectID,   string  groupID, Stream fileStream );

[WebInvoke(Method = "PUT",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "/AddFile")]
Response AddFile(AddFileRequest request, Stream FileStream);

我正在web.config中使用webHttpBinding和webHttp行为。

0 个答案:

没有答案