none
Trouble posting stream with wcf client RRS feed

  • Question

  • I have the following interface for which a service can successfully receive a raw POST from a client like fiddler etc.
    public interface IRestService
    {
        [OperationContract]
        [WebInvoke(
            Method = "POST",
            RequestFormat = WebMessageFormat.Xml,
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "Foo/Submit")]
        void FooSubmit(Stream data);
    }
    I am trying to write a console application to post the same file:
    public class RestClient : ClientBase<IRestService>, IRestService
    {
        public void FooSubmit(Stream data)
        {
            this.Channel.FooSubmit(data);
        }
    }
    Other methods that simply GET text responses work just fine, however I can not POST to this one method:
    using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(strPathFile)))
    using (RestClient restClient = new RestClient())
    {
        restClient.FooSubmit(stream);
    }
    Does anyone know what I am missing?
    Thanks!
    Tuesday, May 19, 2015 5:14 PM

Answers

  • The actual webmethod used an extension on the Stream parameter that was poorly named 'ToString()', however the Stream parameter is seen as an instance of System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream and so the default behavior did not read the stream and convert from bytes but simply assigned the string type name to variable which obviously would not later deserialize.

    Bad idea to ever overload an extension with a name like that...
    • Marked as answer by Ritmo2k Wednesday, May 20, 2015 2:50 AM
    Wednesday, May 20, 2015 2:49 AM

All replies

  • The actual webmethod used an extension on the Stream parameter that was poorly named 'ToString()', however the Stream parameter is seen as an instance of System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream and so the default behavior did not read the stream and convert from bytes but simply assigned the string type name to variable which obviously would not later deserialize.

    Bad idea to ever overload an extension with a name like that...
    • Marked as answer by Ritmo2k Wednesday, May 20, 2015 2:50 AM
    Wednesday, May 20, 2015 2:49 AM
  • Hi Ritmo2k,

    Well Done!

    Thank you very much for sharing this solution to us.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Saturday, May 23, 2015 2:30 AM
    Moderator