Пример #1
0
        /**
         * Calculate String to Sign for SignatureVersion 2
         *
         * @param serviceUri
         *
         * @param parameters
         *            request parameters
         * @return String to Sign
         */
        private static string CalculateStringToSignV2(Uri serviceUri,
                                                      IDictionary <string, string> parameters)
        {
            StringBuilder data = new StringBuilder();

            data.Append("POST");
            data.Append("\n");
            data.Append(serviceUri.Host.ToLower());
            if (!MwsUtil.HasStandardPort(serviceUri))
            {
                data.Append(":");
                data.Append(serviceUri.Port);
            }
            data.Append("\n");
            string uri = serviceUri.LocalPath;

            data.Append(UrlEncode(uri, true));
            data.Append("\n");
            //IDictionary<string, string> sorted = new SortedDictionary<string, string>(parameters, StringComparer.Ordinal);
            IEnumerator <KeyValuePair <string, string> > pairs = parameters.GetEnumerator();
            bool isFirst = true;

            while (pairs.MoveNext())
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    data.Append("&");
                }
                KeyValuePair <string, string> pair = pairs.Current;
                string key = pair.Key;
                data.Append(MwsUtil.UrlEncode(key, false));
                data.Append("=");
                string value = pair.Value;
                data.Append(MwsUtil.UrlEncode(value, false));
            }
            return(data.ToString());
        }
Пример #2
0
        /// <summary>
        /// Read element value
        /// </summary>
        /// <param name="t">Expected type of the element</param>
        /// <param name="node">XmlNode to be read from</param>
        /// <returns>Value of element</returns>
        private T ReadObject <T>(XmlNode node)
        {
            Type type = typeof(T);

            if (typeof(IMwsObject).IsAssignableFrom(type))
            {
                T mwsObject = MwsUtil.NewInstance <T>();
                BeginObject(node);
                (mwsObject as IMwsObject).ReadFragmentFrom(this);
                EndObject();
                return(mwsObject);
            }
            else if (type == typeof(object))
            {
                return((T)(object)node);
            }
            else
            {
                return(ConvertValue <T>(node.InnerText));
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a MwsCall and sends the request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="requestData"></param>
        /// <returns></returns>

        public T Call <T>(IMwsRequestType <T> type,
                          IMwsObject requestData) where T : IMwsObject
        {
            IMwsReader responseReader = null;

            try
            {
                string   servicePath   = type.ServicePath;
                string   operationName = type.OperationName;
                IMwsCall mc            = NewCall(servicePath, operationName);
                requestData.WriteFragmentTo(mc);
                responseReader = mc.invoke();
                MwsResponseHeaderMetadata rhmd = mc.GetResponseMetadataHeader();
                T response = MwsUtil.NewInstance <T>();
                type.SetResponseHeaderMetadata(response, rhmd);
                response.ReadFragmentFrom(responseReader);
                return(response);
            }
            catch (Exception e)
            {
                throw type.WrapException(e);
            }
        }