Exemple #1
0
        internal void BeforeRequest(ref ProxyRpc rpc)
        {
            int offset = _parent.ParameterInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < _parameterInspectors.Length; i++)
                {
                    rpc.Correlation[offset + i] = _parameterInspectors[i].BeforeCall(_name, rpc.InputParameters);
                    if (WcfEventSource.Instance.ClientParameterInspectorBeforeCallInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.ClientParameterInspectorBeforeCallInvoked(rpc.EventTraceActivity, _parameterInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }

            if (_serializeRequest)
            {
                if (WcfEventSource.Instance.ClientFormatterSerializeRequestStartIsEnabled())
                {
                    WcfEventSource.Instance.ClientFormatterSerializeRequestStart(rpc.EventTraceActivity);
                }

                rpc.Request = _formatter.SerializeRequest(rpc.MessageVersion, rpc.InputParameters);



                if (WcfEventSource.Instance.ClientFormatterSerializeRequestStopIsEnabled())
                {
                    WcfEventSource.Instance.ClientFormatterSerializeRequestStop(rpc.EventTraceActivity);
                }
            }
            else
            {
                if (rpc.InputParameters[0] == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxProxyRuntimeMessageCannotBeNull, _name)));
                }

                rpc.Request = (Message)rpc.InputParameters[0];
                if (!IsValidAction(rpc.Request, Action))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInvalidRequestAction, this.Name, rpc.Request.Headers.Action ?? "{NULL}", this.Action)));
                }
            }
        }
Exemple #2
0
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Message message = _innerClientFormatter.SerializeRequest(messageVersion, parameters);

            if (_controller != null)
            {
                _controller.Encode(_context, message);
            }
            return(message);
        }
        Message IClientMessageFormatter.SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            var result = new object[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                result[i] = Serializer.SerializeBytes(parameters[i]);
            }

            return(_innerClientFormatter.SerializeRequest(messageVersion, result));
        }
Exemple #4
0
        // The method appends a suffix to each string parameter and serializes
        // the parameters using the passed in inner formatter.
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            object[] newParams = new object[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                if (parameters[i] is string)
                {
                    newParams[i] = parameters[i] + _suffix;
                }
                else
                {
                    newParams[i] = parameters[i];
                }
            }

            return(_inner.SerializeRequest(messageVersion, newParams));
        }
Exemple #5
0
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            T             data            = null;
            string        body            = string.Empty;
            XmlSerializer serializer      = new XmlSerializer(typeof(T));
            Message       originalMessage = originalFormatter.SerializeRequest(messageVersion, parameters);

            foreach (object parameter in parameters)
            {
                if (parameter is T)
                {
                    data = parameter as T;
                    break;
                }
            }

            if (data == null)
            {
                return(originalMessage);
            }

            using (StringWriter bodyWriter = new StringWriter())
            {
                serializer.Serialize(bodyWriter, data);
                body = bodyWriter.ToString();
            }

            body = new XDocument(
                new XElement(XName.Get("entry", ServiceBusConstants.AtomNamespaceName),
                             new XElement(XName.Get("content", ServiceBusConstants.AtomNamespaceName),
                                          new XAttribute("type", "application/xml"),
                                          XDocument.Parse(body).Root))).ToString();
            Message finalMessage = Message.CreateMessage(messageVersion, null, new CustomBodyWriter(body));

            finalMessage.Headers.CopyHeadersFrom(originalMessage);
            finalMessage.Properties.CopyProperties(originalMessage.Properties);
            HttpRequestMessageProperty property = finalMessage.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

            property.Headers.Add("content-type", "application/xml");
            property.Headers.Add("type", "entry");
            property.Headers.Add("charset", "utf-8");

            return(finalMessage);
        }
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Message newMessage = null;
            var     message    = original.SerializeRequest(messageVersion, parameters);

            if (message.Headers.Action == "urn:Mage_Api_Model_Server_HandlerAction")
            {
                var doc = new XmlDocument();
                using (var reader = message.GetReaderAtBodyContents())
                {
                    doc.Load(reader);
                }
                if (doc.DocumentElement != null)
                {
                    switch (doc.DocumentElement.LocalName)
                    {
                    case "call":
                        AddArrayNamespace(doc.SelectSingleNode("//args"));
                        break;
                    }
                }
                var ms = new MemoryStream();
                XmlWriterSettings ws = new XmlWriterSettings
                {
                    CloseOutput = false,
                };
                using (var xw = XmlWriter.Create(ms, ws))
                {
                    doc.Save(xw);
                    xw.Flush();
                }
                Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
                ms.Position = 0;
                var xr = XmlReader.Create(ms);
                newMessage = Message.CreateMessage(message.Version, null, xr);
                newMessage.Headers.CopyHeadersFrom(message);
                newMessage.Properties.CopyProperties(message.Properties);
            }
            return(newMessage);
        }
Exemple #7
0
        public void RequestClientFormatter2()
        {
            var se = CreateEndpoint();
            var od = se.Contract.Operations [0];
            var b  = new WebHttpBehaviorExt();
            IClientMessageFormatter rcf = null;

            b.ApplyClientBehaviorInvoked += delegate(ServiceEndpoint e, ClientRuntime cr) {
                rcf = cr.Operations [0].Formatter;
            };
            se.Behaviors.Add(b);
            var ch  = new WebChannelFactory <IMyServiceClient> (se).CreateChannel();
            var msg = rcf.SerializeRequest(MessageVersion.None, new object [] { "foo" });
            var hp  = msg.Properties [HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

            Assert.IsNotNull(hp, "#1");
            Assert.IsTrue(msg.IsEmpty, "#2");
            Assert.AreEqual(String.Empty, hp.QueryString, "#3");
            //var mb = msg.CreateBufferedCopy (1000);

            // TODO: test DeserializeReply too (it is supported unlike above).
        }
Exemple #8
0
 public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
 {
     return(baseFormatter.SerializeRequest(messageVersion, parameters));
 }
Exemple #9
0
        public System.ServiceModel.Channels.Message SerializeRequest(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters)
        {
            Message ora_msg = clientFormatter.SerializeRequest(messageVersion, parameters);

            return(Base64BodyMessage(ora_msg));
        }
Exemple #10
0
 public Message SerializeRequest(MessageVersion messageVersion, object [] parameters)
 {
     return(request.SerializeRequest(messageVersion, parameters));
 }
Exemple #11
0
 public override Message ToMessage(
     object typedMessage, MessageVersion version)
 {
     return(formatter.SerializeRequest(version, new object [] { typedMessage }));
 }
 public System.ServiceModel.Channels.Message SerializeRequest(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters)
 {
     return(_baseFormater.SerializeRequest(messageVersion, parameters));
 }
        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            object[]            innerParameters = new object[parameters.Length - this.totalNumUTVars];
            NameValueCollection nvc             = new NameValueCollection();
            int j = 0;

            for (int i = 0; i < parameters.Length; ++i)
            {
                if (this.pathMapping.ContainsKey(i))
                {
                    nvc[this.pathMapping[i]] = parameters[i] as string;
                }
                else if (this.queryMapping.ContainsKey(i))
                {
                    if (parameters[i] != null)
                    {
                        nvc[this.queryMapping[i].Key] = this.qsc.ConvertValueToString(parameters[i], this.queryMapping[i].Value);
                    }
                }
                else
                {
                    innerParameters[j] = parameters[i];
                    ++j;
                }
            }
            Message m = inner.SerializeRequest(messageVersion, innerParameters);
            bool    userSetTheToOnMessage         = (this.innerIsUntypedMessage && m.Headers.To != null);
            bool    userSetTheToOnOutgoingHeaders = (OperationContext.Current != null && OperationContext.Current.OutgoingMessageHeaders.To != null);

            if (!userSetTheToOnMessage && !userSetTheToOnOutgoingHeaders)
            {
                m.Headers.To = this.uriTemplate.BindByName(this.baseUri, nvc);
            }
            if (WebOperationContext.Current != null)
            {
                if (isGet)
                {
                    WebOperationContext.Current.OutgoingRequest.SuppressEntityBody = true;
                }
                if (this.method != WebHttpBehavior.WildcardMethod && WebOperationContext.Current.OutgoingRequest.Method != null)
                {
                    WebOperationContext.Current.OutgoingRequest.Method = this.method;
                }
            }
            else
            {
                HttpRequestMessageProperty hrmp;
                if (m.Properties.ContainsKey(HttpRequestMessageProperty.Name))
                {
                    hrmp = m.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
                }
                else
                {
                    hrmp = new HttpRequestMessageProperty();
                    m.Properties.Add(HttpRequestMessageProperty.Name, hrmp);
                }
                if (isGet)
                {
                    hrmp.SuppressEntityBody = true;
                }
                if (this.method != WebHttpBehavior.WildcardMethod)
                {
                    hrmp.Method = this.method;
                }
            }
            return(m);
        }