http://bugzilla.novell.com/show_bug.cgi?id=619542

http://bugzilla.novell.com/show_bug.cgi?id=619542#c0


           Summary: webHttpBinging is generating wrong responses for
                    methods that return a Stream
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: Macintosh
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: WCF
        AssignedTo: atsu...@ximian.com
        ReportedBy: clovis.ribe...@myabcm.com
         QAContact: mono-bugs@lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us)
AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16

If you write a code like the one below and implement the service, the Microsoft
NET Framework webHttpBinding will understand that you don't want to have the
serialized stream serialized but simply the contents of the stream itself
serialized!

    [ServiceContract]
    public interface IClientAccessPolicy
    {
        [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
        Stream GetClientAccessPolicy();
    }

Our implementation of GetClientAccessPolicy() is doing the following:

        [OperationBehavior]
        public Stream GetClientAccessPolicy()
        {
            #region "Definition dinamic of ClientAccessPolicy.xml file"

            const string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                    <access-policy>
                                        <cross-domain-access>
                                            <policy>
                                                <allow-from
http-request-headers=""*"">
                                                    <domain uri=""http://*""/>
                                                    <domain uri=""https://*""/>
                                                </allow-from>
                                                <grant-to>
                                                    <resource path=""/""
include-subpaths=""true""/>
                                                </grant-to>
                                            </policy>
                                        </cross-domain-access>
                                    </access-policy>";

            #endregion

            if (WebOperationContext.Current != null)
                WebOperationContext.Current.OutgoingResponse.ContentType =
"application/xml";
            return new MemoryStream(Encoding.UTF8.GetBytes(result));
        }

In Windows (NET Framework) this returns the exact XML code back to the browser,
but in Mono, it returns the Stream object itself serialized.

In short, when getting a method that returns a Stream and is decorated with
WebGetAttribute, the serializer should simply return the stream contents
instead of the serialized stream.

I know this is a bit weird but this is the way Microsoft .NET Works.

Reproducible: Always

Steps to Reproduce:
You can test a code like the one below in MS.NET and Mono (I got this simple
example at http://forums.silverlight.net/forums/p/22952/81273.aspx):

    // define the service contract
    [ServiceContract]
    public interface IFileHost
    {
        [OperationContract, WebGet(UriTemplate = "Files/{filename}")]
        Stream Files(string filename);
    }

    // implement the service contract
    public class Service : IFileHost
    {

        public Stream Files(string filename)
        {
            Stream stream = (Stream)new FileStream(filename, FileMode.Open);

            //Set the correct context type for the file requested.
            int extIndex = filename.LastIndexOf(".");
            string extension = filename.Substring(extIndex, filename.Length -
extIndex);
            switch(extension)
            {
                case ".html":
                case ".htm":
                    WebOperationContext.Current.OutgoingResponse.ContentType =
"text/html";
                    break;
                case ".xap":
                    WebOperationContext.Current.OutgoingResponse.ContentType =
"application/x-silverlight-2-b2";
                    break;
                default:
                    throw(new ApplicationException("File type not supported"));
            }

            return stream;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            string baseAddress = "http://"; + Environment.MachineName +
":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new
Uri(baseAddress));
            host.AddServiceEndpoint(typeof(IFileHost), new WebHttpBinding(),
"").Behaviors.Add(new WebHttpBehavior());
            host.Open();
            Console.WriteLine("Service is running");
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();

        }
    }
Actual Results:  
The result in Mono will be a corrupted file

Expected Results:  
The actual file contents

When I got this problem, I decided to implement a MessageInspector and Manually
change the message contents as I really needed to return a raw XML file to the
client in Mono. That's when I got another bug already recorded (bug# 619534)

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
_______________________________________________
mono-bugs maillist  -  mono-bugs@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to