0

I am trying to create a wcf rest service using visual studio 2012 and .net framework 4.5. The service will try to upload a file together with 4 or more parameters. I want to do this in only one call. I want to use the http "put" method. But I keep having these 2 errors.

Operation 'AddFile' in contract 'IRestBasketService' has multiple request body parameters, one of which is a Stream. When the Stream is a parameter, there can be no other parameters in the body. (When I am using BodyStyle wrapped)

and

Operation 'AddFile' of contract 'IRestBasketService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped. (When I am using BodyStyle bare)

What should I do ?

Bellow are the 2 signatures giving me the errors

 [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);

I'm using the webHttpBinding and the webHttp behaviour in the web.config.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171

1 Answers1

1

Since you're using Stream as one of the input parameter, there can be no other parameters in the body. You would need to add all the extra data as part of the stream in the client and then parse it in the service.

1. Similar problem 2. Similar problem

Community
  • 1
  • 1
tatigo
  • 2,174
  • 1
  • 26
  • 32