Beispiel #1
0
        /// <summary>
        /// Prepares to send a request to the Service Provider as the query string in a GET request.
        /// </summary>
        /// <param name="requestMessage">The message to be transmitted to the ServiceProvider.</param>
        /// <returns>The web request ready to send.</returns>
        /// <remarks>
        /// This method is simply a standard HTTP Get request with the message parts serialized to the query string.
        /// This method satisfies OAuth 1.0 section 5.2, item #3.
        /// </remarks>
        protected virtual HttpWebRequest InitializeRequestAsGet(IDirectedProtocolMessage requestMessage)
        {
            ErrorUtilities.VerifyArgumentNotNull(requestMessage, "requestMessage");

            var serializer = MessageSerializer.Get(requestMessage.GetType());
            var fields     = serializer.Serialize(requestMessage);

            UriBuilder builder = new UriBuilder(requestMessage.Recipient);

            MessagingUtilities.AppendQueryArgs(builder, fields);
            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(builder.Uri);

            return(httpRequest);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the URI that, when requested with an HTTP GET request,
        /// would transmit the message that normally would be transmitted via a user agent redirect.
        /// </summary>
        /// <param name="channel">The channel to use for encoding.</param>
        /// <returns>
        /// The URL that would transmit the original message.  This URL may exceed the normal 2K limit,
        /// and should therefore be broken up manually and POSTed as form fields when it exceeds this length.
        /// </returns>
        /// <remarks>
        /// This is useful for desktop applications that will spawn a user agent to transmit the message
        /// rather than cause a redirect.
        /// </remarks>
        internal Uri GetDirectUriRequest(Channel channel)
        {
            Requires.NotNull(channel, "channel");

            var message = this.OriginalMessage as IDirectedProtocolMessage;

            if (message == null)
            {
                throw new InvalidOperationException();                 // this only makes sense for directed messages (indirect responses)
            }

            var        fields  = channel.MessageDescriptions.GetAccessor(message).Serialize();
            UriBuilder builder = new UriBuilder(message.Recipient);

            MessagingUtilities.AppendQueryArgs(builder, fields);
            return(builder.Uri);
        }
Beispiel #3
0
        /// <summary>
        /// Encodes an HTTP response that will instruct the user agent to forward a message to
        /// some remote third party using a 301 Redirect GET method.
        /// </summary>
        /// <param name="message">The message to forward.</param>
        /// <param name="fields">The pre-serialized fields from the message.</param>
        /// <returns>The encoded HTTP response.</returns>
        protected virtual UserAgentResponse Create301RedirectResponse(IDirectedProtocolMessage message, IDictionary <string, string> fields)
        {
            ErrorUtilities.VerifyArgumentNotNull(message, "message");
            ErrorUtilities.VerifyArgumentNamed(message.Recipient != null, "message", MessagingStrings.DirectedMessageMissingRecipient);
            ErrorUtilities.VerifyArgumentNotNull(fields, "fields");

            WebHeaderCollection headers = new WebHeaderCollection();
            UriBuilder          builder = new UriBuilder(message.Recipient);

            MessagingUtilities.AppendQueryArgs(builder, fields);
            headers.Add(HttpResponseHeader.Location, builder.Uri.AbsoluteUri);
            Logger.DebugFormat("Redirecting to {0}", builder.Uri.AbsoluteUri);
            UserAgentResponse response = new UserAgentResponse {
                Status          = HttpStatusCode.Redirect,
                Headers         = headers,
                Body            = null,
                OriginalMessage = message
            };

            return(response);
        }