Ejemplo n.º 1
0
        public ISendResult EndSend(IAsyncResult asyncResult)
        {
            //TODO: Should block until result is available.
            object r;

            if (!asyncResults.TryGetValue(asyncResult, out r) || !(r is WcfSendResult))
            {
                return(null);
            }
            else
            {
                WcfSendResult result = r as WcfSendResult;

                // Publish so WCF connector can send a result
                lock (results)
                    results.Add(result.MessageId, result);

                // Notify
                PublishResult(result.MessageId);

                // Remove the result
                lock (asyncResults)
                    asyncResults.Remove(asyncResult);

                return(r as WcfSendResult);
            }
        }
Ejemplo n.º 2
0
            public void WorkSend(object state)
            {
                // Prepare stream
                WcfSendResult result = new WcfSendResult();
                IGraphable data = (IGraphable)state;

                // Create the surrogate
                XmlSerializerSurrogate surrogate = new XmlSerializerSurrogate(Formatter); 
                
                try
                {
                    // Graph the object
                    result.Message = Message.CreateMessage(MessageVersion, "", data, surrogate);
                    result.MessageId = this.MessageId;
                    result.Headers = this.ResponseHeaders;

                    // Validate
                    surrogate.WriteObject(new MemoryStream(), data);
                    result.Code = surrogate.ResultCode;
                    result.Details = surrogate.Details;

                    if ((result.Code != ResultCode.Accepted && result.Code != ResultCode.AcceptedNonConformant)
                        && InvalidResponse != null)
                    {
                        MessageEventArgs mea = new MessageEventArgs(result.Code, result.Details);
                        InvalidResponse(this, mea);
                        InvalidResponse = null; // Don't call retry again! NOTE: This is a single use class.
                        if (mea.Alternate != null)
                        { // An alternate was suggested
                            if (Formatter is IValidatingStructureFormatter) // Turn of validation for fallback
                                (Formatter as IValidatingStructureFormatter).ValidateConformance = false;
                            WorkSend(mea.Alternate);

                        }
                        return;
                    }

                    // Did the operation succeed?
                    if (result.Code != ResultCode.Accepted && result.Code != ResultCode.AcceptedNonConformant)
                    {
                        result.Details = surrogate.Details;
                        result.Message = null;
                    }
                }
                catch (MessageValidationException e)
                {
                    result.Code = ResultCode.Rejected;
                    List<IResultDetail> dtl = new List<IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(surrogate.Details ?? new IResultDetail[0]);
                    result.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    result.Code = ResultCode.Rejected;
                    result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                finally
                {
                    // Set the result
                    this.SendResult = result;

                    // Fire completed event
                    if (Completed != null) Completed(this);
                }

               
            }
Ejemplo n.º 3
0
            public void WorkSend(object state)
            {
                // Prepare stream
                SendResult = new WcfSendResult();
                IGraphable data = null;
                ReceiveResult = new WcfReceiveResult();
                try { data = (IGraphable)state; }
                catch { }


                // Prepare the serializer surrogate
                XmlSerializerSurrogate surrogate = new XmlSerializerSurrogate(Formatter);

                try
                {
                    if (data == null)
                        throw new MessageValidationException("Invalid message structure passed to the connector", data);

                    // Graph the object
                    string soapAction = "";
#if WINDOWS_PHONE
                    SendResult.Message = Message.CreateMessage(MessageVersion, Actions != null && Actions.TryGetValue(state.GetType(), out soapAction) ? soapAction : "none", data, surrogate);
#else
                    SendResult.Message = Message.CreateMessage(MessageVersion, WcfConfiguration != null && WcfConfiguration.Actions.TryGetValue(state.GetType().FullName, out soapAction) ? soapAction : "none", data, surrogate);
#endif
                    if(CustomHeaders != null)
                        SendResult.Message.Headers.CopyHeadersFrom(CustomHeaders);
                    // Validate
#if !WINDOWS_PHONE
                    var graphResult = this.Formatter.Graph(new MemoryStream(), data);
                    SendResult.Code = graphResult.Code;
                    SendResult.Details = graphResult.Details;
                    // Did the operation fail?
                    if (graphResult.Code != ResultCode.Accepted && graphResult.Code != ResultCode.AcceptedNonConformant)
                    {
                        if (InvalidMessage != null)
                        {
                            MessageEventArgs me = new MessageEventArgs(SendResult.Code, surrogate.Details);
                            InvalidMessage(this, me);
                            if (me.Alternate != null)
                            {
                                SendResult.Message = Message.CreateMessage(MessageVersion, soapAction, me.Alternate, surrogate);
                                graphResult = this.Formatter.Graph(new MemoryStream(), data);
                                SendResult.Code = graphResult.Code;
                                SendResult.Details = graphResult.Details;
                            }
                        }
                        else
                        {
                            SendResult.Details = graphResult.Details;
                            SendResult.Message = null;
                        }
                    }
#endif
                }
                catch (MessageValidationException e)
                {
                    SendResult.Code = ResultCode.Rejected;
                    List<IResultDetail> dtl = new List<IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(surrogate.Details ?? new IResultDetail[0]);
                    SendResult.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    SendResult.Code = ResultCode.Rejected;
                    SendResult.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                catch (Exception e)
                {
                    SendResult.Code = ResultCode.Error;
                    SendResult.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                finally
                {
                }

                // Fire completed event
                if (Completed != null) Completed(this);
            }
Ejemplo n.º 4
0
            public void WorkSend(object state)
            {
                // Prepare stream
                SendResult = new WcfSendResult();
                IGraphable data = null;

                ReceiveResult = new WcfReceiveResult();
                try { data = (IGraphable)state; }
                catch { }


                // Prepare the serializer surrogate
                XmlSerializerSurrogate surrogate = new XmlSerializerSurrogate(Formatter);

                try
                {
                    if (data == null)
                    {
                        throw new MessageValidationException("Invalid message structure passed to the connector", data);
                    }

                    // Graph the object
                    string soapAction = "";
#if WINDOWS_PHONE
                    SendResult.Message = Message.CreateMessage(MessageVersion, Actions != null && Actions.TryGetValue(state.GetType(), out soapAction) ? soapAction : "none", data, surrogate);
#else
                    SendResult.Message = Message.CreateMessage(MessageVersion, WcfConfiguration != null && WcfConfiguration.Actions.TryGetValue(state.GetType().FullName, out soapAction) ? soapAction : "none", data, surrogate);
#endif
                    if (CustomHeaders != null)
                    {
                        SendResult.Message.Headers.CopyHeadersFrom(CustomHeaders);
                    }
                    // Validate
#if !WINDOWS_PHONE
                    var graphResult = this.Formatter.Graph(new MemoryStream(), data);
                    SendResult.Code    = graphResult.Code;
                    SendResult.Details = graphResult.Details;
                    // Did the operation fail?
                    if (graphResult.Code != ResultCode.Accepted && graphResult.Code != ResultCode.AcceptedNonConformant)
                    {
                        if (InvalidMessage != null)
                        {
                            MessageEventArgs me = new MessageEventArgs(SendResult.Code, surrogate.Details);
                            InvalidMessage(this, me);
                            if (me.Alternate != null)
                            {
                                SendResult.Message = Message.CreateMessage(MessageVersion, soapAction, me.Alternate, surrogate);
                                graphResult        = this.Formatter.Graph(new MemoryStream(), data);
                                SendResult.Code    = graphResult.Code;
                                SendResult.Details = graphResult.Details;
                            }
                        }
                        else
                        {
                            SendResult.Details = graphResult.Details;
                            SendResult.Message = null;
                        }
                    }
#endif
                }
                catch (MessageValidationException e)
                {
                    SendResult.Code = ResultCode.Rejected;
                    List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(surrogate.Details ?? new IResultDetail[0]);
                    SendResult.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    SendResult.Code    = ResultCode.Rejected;
                    SendResult.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                catch (Exception e)
                {
                    SendResult.Code    = ResultCode.Error;
                    SendResult.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                finally
                {
                }

                // Fire completed event
                if (Completed != null)
                {
                    Completed(this);
                }
            }
Ejemplo n.º 5
0
            public void WorkSend(object state)
            {
                // Prepare stream
                WcfSendResult result = new WcfSendResult();
                IGraphable    data   = (IGraphable)state;

                // Create the surrogate
                XmlSerializerSurrogate surrogate = new XmlSerializerSurrogate(Formatter);

                try
                {
                    // Graph the object
                    result.Message   = Message.CreateMessage(MessageVersion, "", data, surrogate);
                    result.MessageId = this.MessageId;
                    result.Headers   = this.ResponseHeaders;

                    // Validate
                    surrogate.WriteObject(new MemoryStream(), data);
                    result.Code    = surrogate.ResultCode;
                    result.Details = surrogate.Details;

                    if ((result.Code != ResultCode.Accepted && result.Code != ResultCode.AcceptedNonConformant) &&
                        InvalidResponse != null)
                    {
                        MessageEventArgs mea = new MessageEventArgs(result.Code, result.Details);
                        InvalidResponse(this, mea);
                        InvalidResponse = null;                             // Don't call retry again! NOTE: This is a single use class.
                        if (mea.Alternate != null)
                        {                                                   // An alternate was suggested
                            if (Formatter is IValidatingStructureFormatter) // Turn of validation for fallback
                            {
                                (Formatter as IValidatingStructureFormatter).ValidateConformance = false;
                            }
                            WorkSend(mea.Alternate);
                        }
                        return;
                    }

                    // Did the operation succeed?
                    if (result.Code != ResultCode.Accepted && result.Code != ResultCode.AcceptedNonConformant)
                    {
                        result.Details = surrogate.Details;
                        result.Message = null;
                    }
                }
                catch (MessageValidationException e)
                {
                    result.Code = ResultCode.Rejected;
                    List <IResultDetail> dtl = new List <IResultDetail>(new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) });
                    dtl.AddRange(surrogate.Details ?? new IResultDetail[0]);
                    result.Details = dtl.ToArray();
                }
                catch (FormatException e)
                {
                    result.Code    = ResultCode.Rejected;
                    result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                catch (Exception e)
                {
                    result.Code    = ResultCode.Error;
                    result.Details = new IResultDetail[] { new ResultDetail(ResultDetailType.Error, e.Message, e) };
                }
                finally
                {
                    // Set the result
                    this.SendResult = result;

                    // Fire completed event
                    if (Completed != null)
                    {
                        Completed(this);
                    }
                }
            }