How to send text text to WCF service, i.e. Not packed in XML tag?

Here is my problem:

I have to create a web service that accepts plain text in the body of httppost.
I want to use wcf, but it looks like wcf is for xml / json only.

Does anyone have a method that I can use to publish plain text via an http message?
Please note that I cannot use soap or wrap text inside xml tags, I must follow certain recommendations in order to be compatible with existing users of the service.

Thanks in advance.

+5
source share
1 answer

, Stream xxx

iContract

[WebInvoke(Method = "POST",
    UriTemplate = "InterpSvcTest",
    BodyStyle = WebMessageBodyStyle.Bare)] // this is key for combining params with Stream

Stream InterpretORUTest(Stream ORU);

WebService

    public Stream InterpretORUTest(Stream ORUMessageStream)
    {
        string hl7 = StreamToString(ORUMessageStream);

        return StringToStream(hl7);

    }

   public Stream StringToStream(string s)
        {
            return new MemoryStream(Encoding.UTF8.GetBytes(s));

        }

        public string StreamToString(Stream ms)
        {
            try
            {
                using (ms)
                {
                    var sr = new StreamReader(ms);
                    var myStr = sr.ReadToEnd();
                    sr.Dispose();
                    return myStr;
                };
            }
            catch (Exception e)
            {
                c.WriteToLog("StreamToString error - " + e.Message);
                return "";

            }

        }
0

All Articles