protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory) : base(context.Binding)
        {
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> collection = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (collection.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MultipleMebesInParameters")));
            }
            if (collection.Count == 1)
            {
                this.messageEncoderFactory = collection[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            if (this.messageEncoderFactory != null)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
            }
        }
 public MtomMessageEncoder(System.ServiceModel.Channels.MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, int maxBufferSize, XmlDictionaryReaderQuotas quotas)
 {
     if (version == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("version");
     }
     if (writeEncoding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
     }
     TextEncoderDefaults.ValidateEncoding(writeEncoding);
     this.writeEncoding = writeEncoding;
     this.maxReadPoolSize = maxReadPoolSize;
     this.maxWritePoolSize = maxWritePoolSize;
     this.readerQuotas = new XmlDictionaryReaderQuotas();
     quotas.CopyTo(this.readerQuotas);
     this.maxBufferSize = maxBufferSize;
     this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(this.ReturnStreamedReader);
     this.thisLock = new object();
     if (version.Envelope == EnvelopeVersion.Soap12)
     {
         this.contentEncodingMap = TextMessageEncoderFactory.Soap12Content;
     }
     else
     {
         if (version.Envelope != EnvelopeVersion.Soap11)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid MessageVersion", new object[0])));
         }
         this.contentEncodingMap = TextMessageEncoderFactory.Soap11Content;
     }
     this.version = version;
 }
 protected TransportOutputChannel(ChannelManagerBase channelManager, EndpointAddress to, Uri via, bool manualAddressing, System.ServiceModel.Channels.MessageVersion messageVersion) : base(channelManager)
 {
     this.manualAddressing = manualAddressing;
     this.messageVersion = messageVersion;
     this.to = to;
     this.via = via;
     if (!manualAddressing && (to != null))
     {
         Uri anonymousUri;
         if (to.IsAnonymous)
         {
             anonymousUri = this.messageVersion.Addressing.AnonymousUri;
         }
         else if (to.IsNone)
         {
             anonymousUri = this.messageVersion.Addressing.NoneUri;
         }
         else
         {
             anonymousUri = to.Uri;
         }
         XmlDictionaryString dictionaryTo = new ToDictionary(anonymousUri.AbsoluteUri).To;
         this.toHeader = ToHeader.Create(anonymousUri, dictionaryTo, messageVersion.Addressing);
         this.anyHeadersToAdd = to.Headers.Count > 0;
     }
 }
Пример #4
0
 public MtomMessageEncoder(System.ServiceModel.Channels.MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, int maxBufferSize, XmlDictionaryReaderQuotas quotas)
 {
     if (version == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("version");
     }
     if (writeEncoding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
     }
     TextEncoderDefaults.ValidateEncoding(writeEncoding);
     this.writeEncoding    = writeEncoding;
     this.maxReadPoolSize  = maxReadPoolSize;
     this.maxWritePoolSize = maxWritePoolSize;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     quotas.CopyTo(this.readerQuotas);
     this.maxBufferSize         = maxBufferSize;
     this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(this.ReturnStreamedReader);
     this.thisLock = new object();
     if (version.Envelope == EnvelopeVersion.Soap12)
     {
         this.contentEncodingMap = TextMessageEncoderFactory.Soap12Content;
     }
     else
     {
         if (version.Envelope != EnvelopeVersion.Soap11)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid MessageVersion", new object[0])));
         }
         this.contentEncodingMap = TextMessageEncoderFactory.Soap11Content;
     }
     this.version = version;
 }
Пример #5
0
        public void EchoStringTest(MessageVersion messageVersion, System.ServiceModel.Channels.MessageVersion clientMessageVersion)
        {
            string testString     = new string('a', 10);
            var    webHostBuilder = ServiceHelper.CreateWebHostBuilder <Startup>(_output);

            webHostBuilder.ConfigureServices(services => services.AddServiceModelServices());
            webHostBuilder.Configure(app =>
            {
                app.UseServiceModel(builder =>
                {
                    builder.AddService <Services.TestService>();
                    builder.AddServiceEndpoint <Services.TestService, ServiceContract.ITestService>(Startup.GetServerBinding(messageVersion), "/MessageVersionTest.svc");
                });
            });
            var host = webHostBuilder.Build();

            using (host)
            {
                host.Start();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(Startup.GetClientBinding(clientMessageVersion),
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + "/MessageVersionTest.svc"));
                ClientContract.ITestService channel = factory.CreateChannel();
                var result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                ((System.ServiceModel.IClientChannel)channel).Close();
            }
        }
Пример #6
0
 protected TransportOutputChannel(ChannelManagerBase channelManager, EndpointAddress to, Uri via, bool manualAddressing, System.ServiceModel.Channels.MessageVersion messageVersion) : base(channelManager)
 {
     this.manualAddressing = manualAddressing;
     this.messageVersion   = messageVersion;
     this.to  = to;
     this.via = via;
     if (!manualAddressing && (to != null))
     {
         Uri anonymousUri;
         if (to.IsAnonymous)
         {
             anonymousUri = this.messageVersion.Addressing.AnonymousUri;
         }
         else if (to.IsNone)
         {
             anonymousUri = this.messageVersion.Addressing.NoneUri;
         }
         else
         {
             anonymousUri = to.Uri;
         }
         XmlDictionaryString dictionaryTo = new ToDictionary(anonymousUri.AbsoluteUri).To;
         this.toHeader        = ToHeader.Create(anonymousUri, dictionaryTo, messageVersion.Addressing);
         this.anyHeadersToAdd = to.Headers.Count > 0;
     }
 }
Пример #7
0
        public bool TestIndigoService(string server)
        {
            try
            {
                IndigoService.ServiceTwoWaysVoidNonTransactionalClient proxy = new BizTalk_Benchmark_Wizard.IndigoService.ServiceTwoWaysVoidNonTransactionalClient("IndigoService");

                System.ServiceModel.EndpointAddress newAddress =
                    new System.ServiceModel.EndpointAddress(string.Format("{0}://{1}:{2}{3}",
                                                                          proxy.Endpoint.Address.Uri.Scheme,
                                                                          server,
                                                                          proxy.Endpoint.Address.Uri.Port.ToString(),
                                                                          proxy.Endpoint.Address.Uri.AbsolutePath));

                proxy.Endpoint.Address = newAddress;

                string xml = "<Response><resp>This is a response</resp></Response>";

                using (proxy as IDisposable)
                {
                    System.ServiceModel.Channels.MessageVersion version = System.ServiceModel.Channels.MessageVersion.Soap12WSAddressing10;
                    MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(xml), 0, Encoding.Default.GetBytes(xml).Length);
                    stream.Seek(0L, SeekOrigin.Begin);
                    XmlTextReader reader = new XmlTextReader(stream);
                    System.ServiceModel.Channels.Message request = System.ServiceModel.Channels.Message.CreateMessage(version, "http://tempuri.org/IServiceTwoWaysVoidNonTransactional/ConsumeMessage", (XmlReader)reader);


                    proxy.ConsumeMessage(request);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #8
0
        private static MessageVersion ConvertMessageVersion(System.ServiceModel.Channels.MessageVersion version)
        {
            EnvelopeVersion envelopeVersion = null;

            if (System.ServiceModel.EnvelopeVersion.None.Equals(version.Envelope))
            {
                envelopeVersion = EnvelopeVersion.None;
            }
            else if (System.ServiceModel.EnvelopeVersion.Soap11.Equals(version.Envelope))
            {
                envelopeVersion = EnvelopeVersion.Soap11;
            }
            else if (System.ServiceModel.EnvelopeVersion.Soap12.Equals(version.Envelope))
            {
                envelopeVersion = EnvelopeVersion.Soap12;
            }

            AddressingVersion addressingVersion = null;

            if (System.ServiceModel.Channels.AddressingVersion.None.Equals(version.Addressing))
            {
                addressingVersion = AddressingVersion.None;
            }
            else if (System.ServiceModel.Channels.AddressingVersion.WSAddressing10.Equals(version.Addressing))
            {
                addressingVersion = AddressingVersion.WSAddressing10;
            }
            else if (System.ServiceModel.Channels.AddressingVersion.WSAddressingAugust2004.Equals(version.Addressing))
            {
                addressingVersion = AddressingVersion.WSAddressingAugust2004;
            }

            return(MessageVersion.CreateVersion(envelopeVersion, addressingVersion));
        }
Пример #9
0
 public void ProvideFault(System.Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
 {
     if (error != null)
     {
         Tgnet.Log.LoggerResolver.Current.Error(Keyword, error);
     }
 }
Пример #10
0
 internal static System.ServiceModel.Channels.Binding GetClientBinding(System.ServiceModel.Channels.MessageVersion clientMessageVersion)
 {
     return(new System.ServiceModel.Channels.CustomBinding(
                new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement {
         MessageVersion = clientMessageVersion
     },
                new System.ServiceModel.Channels.TcpTransportBindingElement()));
 }
Пример #11
0
        /// <summary>
        /// Prove as informações da falha.
        /// </summary>
        /// <param name="error"></param>
        /// <param name="version"></param>
        /// <param name="fault"></param>
        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            var prop = new System.ServiceModel.Channels.HttpResponseMessageProperty();

            prop.Headers[System.Net.HttpResponseHeader.ContentType] = "application/json; charset=utf-8";
            fault = System.ServiceModel.Channels.Message.CreateMessage(version, null, new RawBodyWriter(error));
            fault.Properties.Add(System.ServiceModel.Channels.HttpResponseMessageProperty.Name, prop);
            fault.Properties.Add(System.ServiceModel.Channels.WebBodyFormatMessageProperty.Name, new System.ServiceModel.Channels.WebBodyFormatMessageProperty(System.ServiceModel.Channels.WebContentFormat.Json));
        }
Пример #12
0
 public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
 {
     if (error == null)
     {
         return;
     }
     log4net.ILog logger = log4net.LogManager.GetLogger("RecursosHumanosService");
     logger.Error(" *** Error Message : " + error.Message + " *** " + "\\n *** StackTrace : " + error.StackTrace + " *** ");
 }
Пример #13
0
 private TextMessageEncodingBindingElement(TextMessageEncodingBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.maxReadPoolSize  = elementToBeCloned.maxReadPoolSize;
     this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
     this.writeEncoding  = elementToBeCloned.writeEncoding;
     this.messageVersion = elementToBeCloned.messageVersion;
 }
Пример #14
0
 private BinaryMessageEncodingBindingElement(BinaryMessageEncodingBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.maxReadPoolSize  = elementToBeCloned.maxReadPoolSize;
     this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
     this.MaxSessionSize = elementToBeCloned.MaxSessionSize;
     this.BinaryVersion  = elementToBeCloned.BinaryVersion;
     this.messageVersion = elementToBeCloned.messageVersion;
 }
Пример #15
0
 public BinaryMessageEncodingBindingElement()
 {
     this.maxReadPoolSize  = 0x40;
     this.maxWritePoolSize = 0x10;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas);
     this.maxSessionSize = 0x800;
     this.binaryVersion  = BinaryEncoderDefaults.BinaryVersion;
     this.messageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(BinaryEncoderDefaults.EnvelopeVersion);
 }
 public ReliableOutputConnection(UniqueId id, int maxTransferWindowSize, System.ServiceModel.Channels.MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, TimeSpan initialRtt, bool requestAcks, TimeSpan sendTimeout)
 {
     this.id = id;
     this.messageVersion = messageVersion;
     this.reliableMessagingVersion = reliableMessagingVersion;
     this.sendTimeout = sendTimeout;
     this.strategy = new TransmissionStrategy(reliableMessagingVersion, initialRtt, maxTransferWindowSize, requestAcks, id);
     this.strategy.RetryTimeoutElapsed = new RetryHandler(this.OnRetryTimeoutElapsed);
     this.strategy.OnException = new ComponentExceptionHandler(this.RaiseOnException);
 }
Пример #17
0
 internal static System.ServiceModel.Channels.Binding GetClientBinding(System.ServiceModel.Channels.MessageVersion clientMessageVersion)
 {
     return(new System.ServiceModel.Channels.CustomBinding(
                new System.ServiceModel.Channels.TextMessageEncodingBindingElement {
         MessageVersion = clientMessageVersion
     },
                new System.ServiceModel.Channels.HttpTransportBindingElement {
         AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous
     }));
 }
 public ReliableOutputConnection(UniqueId id, int maxTransferWindowSize, System.ServiceModel.Channels.MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, TimeSpan initialRtt, bool requestAcks, TimeSpan sendTimeout)
 {
     this.id                           = id;
     this.messageVersion               = messageVersion;
     this.reliableMessagingVersion     = reliableMessagingVersion;
     this.sendTimeout                  = sendTimeout;
     this.strategy                     = new TransmissionStrategy(reliableMessagingVersion, initialRtt, maxTransferWindowSize, requestAcks, id);
     this.strategy.RetryTimeoutElapsed = new RetryHandler(this.OnRetryTimeoutElapsed);
     this.strategy.OnException         = new ComponentExceptionHandler(this.RaiseOnException);
 }
Пример #19
0
 /// <summary>
 /// Processa e fornece uma mensagem sobre o erro ocorrido.
 /// </summary>
 /// <param name="error"></param>
 /// <param name="version"></param>
 /// <param name="fault"></param>
 public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
 {
     if (error is System.ServiceModel.FaultException)
     {
     }
     else
     {
         System.ServiceModel.Channels.MessageFault messageFault = System.ServiceModel.Channels.MessageFault.CreateFault(new System.ServiceModel.FaultCode("Sender"), new System.ServiceModel.FaultReason(error.Message), error, new System.Runtime.Serialization.NetDataContractSerializer());
         fault = System.ServiceModel.Channels.Message.CreateMessage(version, messageFault, null);
     }
 }
Пример #20
0
 public ServiceChannelFactory(System.ServiceModel.Dispatcher.ClientRuntime clientRuntime, Binding binding)
 {
     if (clientRuntime == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clientRuntime");
     }
     this.bindingName    = binding.Name;
     this.channelsList   = new List <IChannel>();
     this.clientRuntime  = clientRuntime;
     this.timeouts       = new DefaultCommunicationTimeouts(binding);
     this.messageVersion = binding.MessageVersion;
 }
 protected ReliableChannelListenerBase(ReliableSessionBindingElement settings, Binding binding) : base(true, binding)
 {
     this.acknowledgementInterval = settings.AcknowledgementInterval;
     this.flowControlEnabled      = settings.FlowControlEnabled;
     this.inactivityTimeout       = settings.InactivityTimeout;
     this.maxPendingChannels      = settings.MaxPendingChannels;
     this.maxRetryCount           = settings.MaxRetryCount;
     this.maxTransferWindowSize   = settings.MaxTransferWindowSize;
     this.messageVersion          = binding.MessageVersion;
     this.ordered = settings.Ordered;
     this.reliableMessagingVersion = settings.ReliableMessagingVersion;
 }
Пример #22
0
        private static ContentEncoding[] GetContentEncodingMap(System.ServiceModel.Channels.MessageVersion version)
        {
            Encoding[] supportedEncodings = GetSupportedEncodings();
            string     mediaType          = GetMediaType(version);

            ContentEncoding[] encodingArray2 = new ContentEncoding[supportedEncodings.Length];
            for (int i = 0; i < supportedEncodings.Length; i++)
            {
                encodingArray2[i] = new ContentEncoding {
                    contentType = GetContentType(mediaType, supportedEncodings[i]), encoding = supportedEncodings[i]
                };
            }
            return(encodingArray2);
        }
Пример #23
0
 public ReliableChannelFactory(ReliableSessionBindingElement settings, IChannelFactory <InnerChannel> innerChannelFactory, Binding binding) : base(binding)
 {
     this.acknowledgementInterval = settings.AcknowledgementInterval;
     this.flowControlEnabled      = settings.FlowControlEnabled;
     this.inactivityTimeout       = settings.InactivityTimeout;
     this.maxPendingChannels      = settings.MaxPendingChannels;
     this.maxRetryCount           = settings.MaxRetryCount;
     this.maxTransferWindowSize   = settings.MaxTransferWindowSize;
     this.messageVersion          = binding.MessageVersion;
     this.ordered = settings.Ordered;
     this.reliableMessagingVersion = settings.ReliableMessagingVersion;
     this.innerChannelFactory      = innerChannelFactory;
     this.faultHelper = new SendFaultHelper(binding.SendTimeout, binding.CloseTimeout);
 }
            public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
            {
                if (error is System.ServiceModel.FaultException)
                {
                    return;
                }

                var identifier = _logDelegate?.Invoke(error);

                var detail = new ExceptionFault(identifier, error, _includeDetails);

                var messageFault = System.ServiceModel.Channels.MessageFault.CreateFault(new System.ServiceModel.FaultCode("Sender"), new System.ServiceModel.FaultReason("UnhandledException"), detail);

                fault = System.ServiceModel.Channels.Message.CreateMessage(version, messageFault, null);
            }
Пример #25
0
 internal static string GetMediaType(System.ServiceModel.Channels.MessageVersion version)
 {
     if (version.Envelope == EnvelopeVersion.Soap12)
     {
         return("application/soap+xml");
     }
     if (version.Envelope == EnvelopeVersion.Soap11)
     {
         return("text/xml");
     }
     if (version.Envelope != EnvelopeVersion.None)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("EnvelopeVersionNotSupported", new object[] { version.Envelope })));
     }
     return("application/xml");
 }
 public BinaryMessageEncoderFactory(System.ServiceModel.Channels.MessageVersion messageVersion, int maxReadPoolSize, int maxWritePoolSize, int maxSessionSize, XmlDictionaryReaderQuotas readerQuotas, BinaryVersion version)
 {
     this.messageVersion = messageVersion;
     this.messageEncoder = new BinaryMessageEncoder(this, false, 0);
     this.maxReadPoolSize = maxReadPoolSize;
     this.maxWritePoolSize = maxWritePoolSize;
     this.maxSessionSize = maxSessionSize;
     this.thisLock = new object();
     this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(this.ReturnStreamedReader);
     this.readerQuotas = new XmlDictionaryReaderQuotas();
     if (readerQuotas != null)
     {
         readerQuotas.CopyTo(this.readerQuotas);
     }
     this.binaryVersion = version;
 }
 public BinaryMessageEncoderFactory(System.ServiceModel.Channels.MessageVersion messageVersion, int maxReadPoolSize, int maxWritePoolSize, int maxSessionSize, XmlDictionaryReaderQuotas readerQuotas, BinaryVersion version)
 {
     this.messageVersion        = messageVersion;
     this.messageEncoder        = new BinaryMessageEncoder(this, false, 0);
     this.maxReadPoolSize       = maxReadPoolSize;
     this.maxWritePoolSize      = maxWritePoolSize;
     this.maxSessionSize        = maxSessionSize;
     this.thisLock              = new object();
     this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(this.ReturnStreamedReader);
     this.readerQuotas          = new XmlDictionaryReaderQuotas();
     if (readerQuotas != null)
     {
         readerQuotas.CopyTo(this.readerQuotas);
     }
     this.binaryVersion = version;
 }
Пример #28
0
 public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
 {
     if (error is FaultException)
     {
         // Let WCF do normal processing
     }
     else
     {
         // Generate fault message manually including the exception as the fault detail
         MessageFault messageFault = MessageFault.CreateFault(
             new FaultCode("Sender"),
             new FaultReason(error.Message),
             error,
             new NetDataContractSerializer());
         fault = Message.CreateMessage(version, messageFault, null);
     }
 }
Пример #29
0
 public TextMessageEncodingBindingElement(System.ServiceModel.Channels.MessageVersion messageVersion, Encoding writeEncoding)
 {
     if (messageVersion == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("messageVersion");
     }
     if (writeEncoding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
     }
     TextEncoderDefaults.ValidateEncoding(writeEncoding);
     this.maxReadPoolSize  = 0x40;
     this.maxWritePoolSize = 0x10;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas);
     this.messageVersion = messageVersion;
     this.writeEncoding  = writeEncoding;
 }
Пример #30
0
        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            if (error == null)
            {
                return;
            }
            /////In case we run outside of IIS,
            /////make sure aspNetCompatibilityEnabled="true" in web.config under system.serviceModel/serviceHostingEnvironment
            /////to be sure that HttpContext.Current is not null
            //if (HttpContext.Current == null)
            //    return;
            //Elmah.ErrorSignal.FromCurrentContext().Raise(error);
            //Elmah.ErrorSignal.FromContext(null).Raise(error);


            //TODO: Enable when Elmah added
            //Log(error);
        }
Пример #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="error"></param>
        /// <param name="version"></param>
        /// <param name="fault"></param>
        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            if (error is FaultException <ValidationFault> || error is ArgumentValidationException)
            {
                var action     = OperationContext.Current.IncomingMessageHeaders.Action;
                var operations = OperationContext.Current.EndpointDispatcher.DispatchRuntime.Operations;
                var operation  = operations.Where(d => d.Action == action).FirstOrDefault( );
                if (operation != null)
                {
                    var method     = TypeDescriptor.GetProperties(operation.Invoker)["Method"].GetValue(operation.Invoker);
                    var returnType = ( Type )TypeDescriptor.GetProperties(method)["ReturnType"].GetValue(method);
                    IList <ValidationDetail> details = null;
                    if (error is FaultException <ValidationFault> )
                    {
                        details = (error as FaultException <ValidationFault>).Detail.Details;
                    }
                    else
                    {
                        var tmp = (error as ArgumentValidationException).ValidationResults;
                        details = tmp.Select(r => new ValidationDetail(r.Message, r.Key, r.Tag)).ToList( );
                    }


                    // 先判断是否有静态方法 Create
                    var create = returnType.GetMethod("Create", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, new Type[] { typeof(IList <ValidationDetail>) }, null);
                    if (create != null)
                    {
                        if (create.IsGenericMethod)
                        {
                            create = create.MakeGenericMethod(returnType);
                        }
                        var value = create.Invoke(null, new object[] { details });

                        fault = operation.Formatter.SerializeReply(version, new object[] { }, value);
                    }
                    else if (returnType.GetConstructor(new Type[] { typeof(IList <ValidationDetail>) }) != null)
                    {
                        var value = Activator.CreateInstance(returnType, details);
                        fault = operation.Formatter.SerializeReply(version, new object[] { }, value);
                    }
                }
            }
        }
Пример #32
0
 public TextMessageEncoder(System.ServiceModel.Channels.MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
 {
     if (version == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("version");
     }
     if (writeEncoding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
     }
     TextEncoderDefaults.ValidateEncoding(writeEncoding);
     this.writeEncoding        = writeEncoding;
     this.optimizeWriteForUTF8 = IsUTF8Encoding(writeEncoding);
     this.thisLock             = new object();
     this.version          = version;
     this.maxReadPoolSize  = maxReadPoolSize;
     this.maxWritePoolSize = maxWritePoolSize;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     quotas.CopyTo(this.readerQuotas);
     this.onStreamedReaderClose = new OnXmlDictionaryReaderClose(this.ReturnStreamedReader);
     this.mediaType             = TextMessageEncoderFactory.GetMediaType(version);
     this.contentType           = TextMessageEncoderFactory.GetContentType(this.mediaType, writeEncoding);
     if (version.Envelope == EnvelopeVersion.Soap12)
     {
         this.contentEncodingMap = TextMessageEncoderFactory.Soap12Content;
     }
     else if (version.Envelope == EnvelopeVersion.Soap11)
     {
         this.contentEncodingMap = TextMessageEncoderFactory.Soap11Content;
     }
     else
     {
         if (version.Envelope != EnvelopeVersion.None)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("EnvelopeVersionNotSupported", new object[] { version.Envelope })));
         }
         this.contentEncodingMap = TextMessageEncoderFactory.SoapNoneContent;
     }
 }
Пример #33
0
 public MtomMessageEncodingBindingElement(System.ServiceModel.Channels.MessageVersion messageVersion, Encoding writeEncoding)
 {
     if (messageVersion == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("messageVersion");
     }
     if (messageVersion == System.ServiceModel.Channels.MessageVersion.None)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MtomEncoderBadMessageVersion", new object[] { messageVersion.ToString() }), "messageVersion"));
     }
     if (writeEncoding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
     }
     TextEncoderDefaults.ValidateEncoding(writeEncoding);
     this.maxReadPoolSize  = 0x40;
     this.maxWritePoolSize = 0x10;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas);
     this.maxBufferSize  = 0x10000;
     this.messageVersion = messageVersion;
     this.writeEncoding  = writeEncoding;
 }
Пример #34
0
 public TextMessageEncoderFactory(System.ServiceModel.Channels.MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
 {
     this.messageEncoder = new TextMessageEncoder(version, writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas);
 }