none
File upload with REST/WCF Error: The operation must have a single parameter whose type is Stream RRS feed

  • Question

  • I am creating a service similar to this example:

    http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx

    where I have the following function:

            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/UploadFile/{project}/{description}/{filecontents}")]
            UploadResponse UploadFile(string project, string filename, string description, Stream filecontents);


    where upon hitting the service url with a browser or creating a service reference in a web project I get the following error - The operation must have a single parameter whose type is Stream.

    The blog by Carlos specifies "the operation can have other parameters beside the Stream one, as long as they're used in the address (UriTemplate) for the operation" which you can see is the case from the example above.  Later in the comments Carlos states "you may be hitting a known bug in WCF (the metadata generation code in WCF isn't aware of the special case for Stream parameters composed with UriTemplate ones)."  I've checked other articles on this issue and I am not sure how I can get around this.  Any ideas?
    Monday, September 30, 2013 8:00 PM

Answers

  • Hi,

    >>as well as tried to create a service reference via Visual Studio.

    "Add Service Reference" to create a proxy for REST (WCF Web HTTP) endpoints in WCF does not work, so do you try using ChannelFactory instead?

    using(ChannelFactory<IEmployees> channelFactory = new ChannelFactory<IEmployees>("employeeService"))
        {
            IEmployees proxy = channelFactory.CreateChannel();
            int result=proxy.Add(1,2);
    //...
    }

    #Mixing Add Service Reference and WCF Web HTTP (a.k.a. REST) endpoint does not work

    http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx

    Thanks.

    Best Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 2, 2013 7:31 AM
    Moderator

All replies

  • Hi,

    >>The blog by Carlos specifies "the operation can have other parameters beside the Stream one, as long as they're used in the address (UriTemplate) for the operation" which you can see is the case from the example above. 

    According to my understanding, as mentioned by Carlos, you need make sure all non-Stream parameters in the operation are bound to the UriTemplate, that is "project", "filename", "description" in your code(not filecontents).

    [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/UploadFile/{project}/{description}/{filename}")]
            UploadResponse UploadFile(string project, string filename, string description, Stream filecontents);

    >>Later in the comments Carlos states "you may be hitting a known bug in WCF (the metadata generation code in WCF isn't aware of the special case for Stream parameters composed with UriTemplate ones)."

    After try modifying as I mentioned above, please check if you get this error when you open the host rather than browse the service address.

    Thanks.

    Best Regards. 


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 1, 2013 6:26 AM
    Moderator
  • Ended up with the same error after I fixed the URI template.  I've tried from the browser(which I assume would not work) as well as tried to create a service reference via Visual Studio.
    Tuesday, October 1, 2013 3:31 PM
  • Hi,

    >>as well as tried to create a service reference via Visual Studio.

    "Add Service Reference" to create a proxy for REST (WCF Web HTTP) endpoints in WCF does not work, so do you try using ChannelFactory instead?

    using(ChannelFactory<IEmployees> channelFactory = new ChannelFactory<IEmployees>("employeeService"))
        {
            IEmployees proxy = channelFactory.CreateChannel();
            int result=proxy.Add(1,2);
    //...
    }

    #Mixing Add Service Reference and WCF Web HTTP (a.k.a. REST) endpoint does not work

    http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx

    Thanks.

    Best Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 2, 2013 7:31 AM
    Moderator