1

我正在尝试使用 Visual Studio 2012 和 .net 框架 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 行为。

4

0 回答 0