Example #1
0
        public void HandleRequest(RequestContext context)
        {
            Debug.Assert(context != null);

            if (context.RequestMessage.Headers.Action == requestAction)
            {
                XmlDictionaryReader    reader     = context.RequestMessage.GetReaderAtBodyContents();
                DataContractSerializer serializer = new DataContractSerializer(typeof(string));
                reader.ReadStartElement(); // read wrapper begin
                string value = (string)serializer.ReadObject(reader, false);
                reader.ReadEndElement();   // read wrapper end

                reader.Close();

                string             result             = serviceInstance.Hello(value);
                ResponseBodyWriter responseBodyWriter = new ResponseBodyWriter(
                    HelloWorldService.OperationName,
                    HelloWorldService.Namespace);
                responseBodyWriter.Result = result;

                MessageVersion requestVersion = context.RequestMessage.Version;
                UniqueId       requestId      = context.RequestMessage.Headers.MessageId;

                Message reply = Message.CreateMessage(requestVersion,
                                                      responseAction,
                                                      responseBodyWriter);

                PrepareReply(reply, requestId);
                if (context.RequestMessage.Headers.ReplyTo != null)
                {
                    reply.Headers.To = context.RequestMessage.Headers.ReplyTo.Uri;
                }

                context.Reply(reply);
            }
            else
            {
                object property = null;
                if (context.RequestMessage.Properties.TryGetValue(HttpRequestMessageProperty.Name,
                                                                  out property))
                {
                    if (string.Compare(((HttpRequestMessageProperty)property).Method, "GET", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        HandleHttpGet(context);
                        return;
                    }
                }

                SendMismatchFault(context);
            }
        }
Example #2
0
        public void HandleRequest(RequestContext context)
        {
            Debug.Assert(context != null);

            if (context.RequestMessage.Headers.Action == requestAction)
            {
                XmlDictionaryReader reader = context.RequestMessage.GetReaderAtBodyContents();
                DataContractSerializer serializer = new DataContractSerializer(typeof(string));
                reader.ReadStartElement(); // read wrapper begin
                string value = (string)serializer.ReadObject(reader, false);
                reader.ReadEndElement(); // read wrapper end

                reader.Close();

                string result = serviceInstance.Hello(value);
                ResponseBodyWriter responseBodyWriter = new ResponseBodyWriter(
                    HelloWorldService.OperationName,
                    HelloWorldService.Namespace);
                responseBodyWriter.Result = result;

                MessageVersion requestVersion = context.RequestMessage.Version;
                UniqueId requestId = context.RequestMessage.Headers.MessageId;

                Message reply = Message.CreateMessage(requestVersion,
                                                      responseAction,
                                                      responseBodyWriter);

                PrepareReply(reply, requestId);
                if (context.RequestMessage.Headers.ReplyTo != null)
                {
                    reply.Headers.To = context.RequestMessage.Headers.ReplyTo.Uri;
                }

                context.Reply(reply);
            }
            else
            {
                object property = null;
                if (context.RequestMessage.Properties.TryGetValue(HttpRequestMessageProperty.Name,
                    out property))
                {
                    if (string.Compare(((HttpRequestMessageProperty)property).Method, "GET", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        HandleHttpGet(context);
                        return;
                    }
                }

                SendMismatchFault(context);
            }
        }