Example #1
0
        /// <summary>
        /// Deserializes an instance of <see cref="WebMethodCallOptions"/> from a <see cref="XElement"/>.
        /// </summary>
        /// <param name="element">The xml element.</param>
        /// <returns>Returns an instance of <see cref="WebMethodCallOptions"/>.</returns>
        /// <exception cref="System.ArgumentNullException">element</exception>
        /// <exception cref="System.InvalidOperationException">The element name is invalid.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="element"/> parameter is null.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="element"/> name is not valid.</exception>
        public static WebMethodCallOptions GetWebMethodCallOptions(XElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            if (element.Name != CallOptionsElementName)
                throw new InvalidOperationException("The element name is invalid.");

            var callOptions = new WebMethodCallOptions();

            var headerAttributesElement = element.Element(HeaderAttributesElementName);
            if (headerAttributesElement != null)
                callOptions.HeaderAttributes.AddRange(
                    headerAttributesElement.Elements(SoapHeaderAttributes.HeaderElementName).Select(SoapHeaderAttributes.CreateHeaderAttributes));

            return callOptions;
        }
        /// <summary>
        /// Serializes web method call options.
        /// </summary>
        /// <param name="options">The options to serialize.</param>
        /// <returns>Returns a <see cref="string" /> representing the serialized <paramref name="options" />.</returns>
        /// <exception cref="System.ArgumentNullException">options</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="options" /> is null.</exception>
        public string SerializeOptions(WebMethodCallOptions options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            return options.GetXElement().ToString();
        }
        /// <summary>
        /// Creates a request.
        /// </summary>
        /// <param name="item">The editable root item to be used as data source.</param>
        /// <returns>Returns a <see cref="WebMethodCallData"/>.</returns>
        private WebMethodCallData CreateRequest(IEditableRoot item)
        {
            var callContext = EditableRootDataContextFactory.CreateDataContext(item);
            var message = Activator.CreateInstance(MethodProxy.RequestType);
            var callOptions = new WebMethodCallOptions();

            foreach (var headerMapping in HeaderAttributesCalculators)
            {
                var headerAttributes = headerMapping.GetHeaderAttributes(callContext);
                if (headerAttributes.IsMustUnderstandSet || headerAttributes.IsActorSet || headerAttributes.IsRelaySet)
                    callOptions.HeaderAttributes.Add(headerAttributes);
            }

            foreach (var propertySetter in RequestPropertySetters)
            {
                propertySetter.Update(callContext, message);
            }

            return new WebMethodCallData { Message = message, Options = callOptions };
        }