【发布时间】:2013-03-09 07:59:19
【问题描述】:
我正在尝试使用 Visual Studio 2012 和 .net Framework 4.5 创建 wcf 休息服务。 该服务将尝试上传包含 4 个或更多参数的文件。我只想在一个电话中做到这一点。我想使用http“put”方法。但我一直有这两个错误。
合约 'IRestBasketService' 中的操作 'AddFile' 有多个请求体参数,其中一个是 Stream。当 Stream 为参数时,body 中不能有其他参数。 (当我使用 BodyStyle 包裹时)
和
合约 'IRestBasketService' 的操作 'AddFile' 指定要序列化的多个请求主体参数,而无需任何包装器元素。最多一个 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 行为。
【问题讨论】:
-
似乎在 UriTemplate 中我遗漏了一个参数(类型)。
-
但是我仍然可以将 json 与流对象一起使用吗?
标签: wcf rest parameters stream