コード例 #1
0
        private void CreateErrorReply(ref RequestContext p_RequestContext)
        {
            var l_Message = new CustomResponse();
            l_Message.Message = "Login Failed";

             using (Message reply = Message.CreateMessage(MessageVersion.None, "", l_Message, new DataContractJsonSerializer(typeof(CustomResponse))))
             {
                 var responseProp = new HttpResponseMessageProperty
                 {
                     StatusCode = HttpStatusCode.Forbidden,
                     StatusDescription = String.Format("Forbidden")
                 };

                 responseProp.Headers.Add("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", Realm));
                 responseProp.Headers[HttpResponseHeader.ContentType] = "application/json; charset=utf-8";
                 reply.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
                 reply.Properties[HttpResponseMessageProperty.Name] = responseProp;

                 p_RequestContext.Reply(reply);
                 // set the request context to null to terminate processing of this request
                 p_RequestContext = null;

             }
        }
コード例 #2
0
        private void CreateSuccessReply(ref RequestContext p_RequestContext, string p_PasswordHash)
        {
            var l_Message = new CustomResponse();
            l_Message.Message = "Login Successful";
            l_Message.Data = p_PasswordHash;

            using (Message reply = Message.CreateMessage(MessageVersion.None, "", l_Message, new DataContractJsonSerializer(typeof(CustomResponse))))
            {
                var responseProp = new HttpResponseMessageProperty
                {
                    StatusCode = HttpStatusCode.Accepted,
                    StatusDescription = String.Format("Accepted")
                };

                responseProp.Headers.Add("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", Realm));
                responseProp.Headers[HttpResponseHeader.ContentType] = "application/json; charset=utf-8";
                reply.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Json));
                reply.Properties[HttpResponseMessageProperty.Name] = responseProp;

                p_RequestContext.Reply(reply);

            }
        }