Пример #1
0
        public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
        {
            if (WebOperationContext.Current.IncomingRequest.ContentType != "application/x-www-form-urlencoded")
            {
                throw new InvalidDataException("Unexpected content type");
            }

            Stream s        = StreamMessageHelper.GetStream(message);
            string formData = new StreamReader(s).ReadToEnd();

            NameValueCollection parsedForm = System.Web.HttpUtility.ParseQueryString(formData);

            UriTemplateMatch match = message.Properties["UriTemplateMatchResults"] as UriTemplateMatch;

            ParameterInfo[] paramInfos = operation.SyncMethod.GetParameters();

            var binder = CreateParameterBinder(match);

            object[] values = (from p in paramInfos
                               select binder(p)).ToArray <Object>();

            values[paramInfos.Length - 1] = parsedForm;

            values.CopyTo(parameters, 0);
        }
Пример #2
0
        public Message ProcessForm(string templateParam1, string templateParam2, NameValueCollection formData)
        {
            DumpValues(Console.Out, templateParam1, templateParam2, formData);

            return(StreamMessageHelper.CreateMessage(MessageVersion.None, "", "text/plain",
                                                     delegate(Stream output)
            {
                TextWriter writer = new StreamWriter(output);
                DumpValues(writer, templateParam1, templateParam2, formData);
            }));
        }
Пример #3
0
        public Message GetDynamicImage()
        {
            string text = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["text"];

            Bitmap theBitmap = GenerateImage(text);

            Message response = StreamMessageHelper.CreateMessage(MessageVersion.None, "", "image/jpeg",
                                                                 delegate(Stream outputStream)
            {
                theBitmap.Save(outputStream, ImageFormat.Jpeg);
            });

            return(response);
        }
Пример #4
0
        public Message GetDynamicText()
        {
            string  text     = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["text"];
            Message response = StreamMessageHelper.CreateMessage(MessageVersion.None, "", "text/plain",

                                                                 delegate(Stream s)
            {
                TextWriter writer = new StreamWriter(s);

                writer.WriteLine("You said: ");
                writer.WriteLine(text);
                writer.WriteLine("Didn't you?");
                writer.Flush();
            });

            return(response);
        }
Пример #5
0
        public Message DisplayForm()
        {
            return(StreamMessageHelper.CreateMessage(MessageVersion.None, "", "text/html",
                                                     delegate(Stream output)
            {
                TextWriter writer = new StreamWriter(output);
                writer.WriteLine(
                    @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
                            <html>
	<head>
		<title></title>
	</head>
	<body>
	    <form action=""http://localhost:8000/FormTest/ProcessForm/X/Y"" method=POST>
	        Foo: <input name=""Foo"" type=""text"" /><br />
	        Bar: <input name=""Bar"" type=""text"" /><br />
            <input name=""Submit1"" type=""submit"" value=""submit"" />
	    </form>
	</body>
</html>");
                writer.Flush();
            }));
        }