示例#1
0
        /*
         #if DEBUG
         * private static void CopyStream(Stream source, Stream dest) {
         *  byte[] bytes = new byte[1024];
         *  int numRead = 0;
         *  while ((numRead = source.Read(bytes, 0, 1024)) > 0)
         *      dest.Write(bytes, 0, numRead);
         * }
         #endif
         */

        private void SetHelper(SoapServerProtocolHelper helper)
        {
            this.helper  = helper;
            this.version = helper.Version;
            // SOAP12: disabled
            //Context.Items[WebService.SoapVersionContextSlot] = helper.Version;
        }
示例#2
0
        internal static SoapServerProtocolHelper GetHelper(SoapServerProtocol protocol)
        {
            SoapServerMessage message   = protocol.Message;
            long          savedPosition = message.Stream.Position;
            XmlTextReader reader        = GetXmlTextReader(message.ContentType, message.Stream);

            reader.MoveToContent();
            string requestNamespace         = reader.NamespaceURI;
            SoapServerProtocolHelper helper = GetHelper(protocol, requestNamespace);

            message.Stream.Position = savedPosition;
            return(helper);
        }
        /*
        #if DEBUG
        private static void CopyStream(Stream source, Stream dest) {
            byte[] bytes = new byte[1024];
            int numRead = 0;
            while ((numRead = source.Read(bytes, 0, 1024)) > 0)
                dest.Write(bytes, 0, numRead);
        }
        #endif
        */

        private void SetHelper(SoapServerProtocolHelper helper) {
            this.helper = helper;
            this.version = helper.Version;
            Context.Items[WebService.SoapVersionContextSlot] = helper.Version;
        }
示例#4
0
 private void SetHelper(SoapServerProtocolHelper helper)
 {
     this.helper  = helper;
     this.version = helper.Version;
     base.Context.Items[WebService.SoapVersionContextSlot] = helper.Version;
 }
示例#5
0
        internal override object[] ReadParameters()
        {
            object[] objArray2;
            this.message.InitExtensionStreamChain(this.message.otherExtensions);
            this.message.RunExtensions(this.message.otherExtensions, true);
            if (!ContentType.IsSoap(this.message.ContentType))
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestContent", new object[] { this.message.ContentType, this.helper.HttpContentType }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), new SoapFaultSubCode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }
            XmlReader xmlReader = null;

            try
            {
                xmlReader = this.GetXmlReader();
                xmlReader.MoveToContent();
                this.SetHelper(SoapServerProtocolHelper.GetHelper(this, xmlReader.NamespaceURI));
            }
            catch (XmlException exception)
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestUnableToRead"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), exception);
            }
            this.CheckHelperVersion();
            if ((this.version == SoapProtocolVersion.Soap11) && !ContentType.MatchesBase(this.message.ContentType, this.helper.HttpContentType))
            {
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestContent", new object[] { this.message.ContentType, this.helper.HttpContentType }), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), new SoapFaultSubCode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }
            if (this.message.Exception != null)
            {
                throw this.message.Exception;
            }
            try
            {
                object[] objArray;
                if (!xmlReader.IsStartElement("Envelope", this.helper.EnvelopeNs))
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingEnvelopeElement"));
                }
                if (xmlReader.IsEmptyElement)
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingBodyElement"));
                }
                int depth = xmlReader.Depth;
                xmlReader.ReadStartElement("Envelope", this.helper.EnvelopeNs);
                xmlReader.MoveToContent();
                bool   checkRequiredHeaders = ((this.serverMethod.wsiClaims & WsiProfiles.BasicProfile1_1) != WsiProfiles.None) && (this.version != SoapProtocolVersion.Soap12);
                string str = new SoapHeaderHandling().ReadHeaders(xmlReader, this.serverMethod.inHeaderSerializer, this.message.Headers, this.serverMethod.inHeaderMappings, SoapHeaderDirection.In, this.helper.EnvelopeNs, (this.serverMethod.use == SoapBindingUse.Encoded) ? this.helper.EncodingNs : null, checkRequiredHeaders);
                if (str != null)
                {
                    throw new SoapHeaderException(System.Web.Services.Res.GetString("WebMissingHeader", new object[] { str }), new XmlQualifiedName("MustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/"));
                }
                if (!xmlReader.IsStartElement("Body", this.helper.EnvelopeNs))
                {
                    throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingBodyElement"));
                }
                xmlReader.ReadStartElement("Body", this.helper.EnvelopeNs);
                xmlReader.MoveToContent();
                bool        flag2  = this.serverMethod.use == SoapBindingUse.Encoded;
                TraceMethod caller = Tracing.On ? new TraceMethod(this, "ReadParameters", new object[0]) : null;
                if (Tracing.On)
                {
                    Tracing.Enter(Tracing.TraceId("TraceReadRequest"), caller, new TraceMethod(this.serverMethod.parameterSerializer, "Deserialize", new object[] { xmlReader, (this.serverMethod.use == SoapBindingUse.Encoded) ? this.helper.EncodingNs : null }));
                }
                if (!flag2 && (WebServicesSection.Current.SoapEnvelopeProcessing.IsStrict || Tracing.On))
                {
                    XmlDeserializationEvents events = Tracing.On ? Tracing.GetDeserializationEvents() : RuntimeUtils.GetDeserializationEvents();
                    objArray = (object[])this.serverMethod.parameterSerializer.Deserialize(xmlReader, null, events);
                }
                else
                {
                    objArray = (object[])this.serverMethod.parameterSerializer.Deserialize(xmlReader, flag2 ? this.helper.EncodingNs : null);
                }
                if (Tracing.On)
                {
                    Tracing.Exit(Tracing.TraceId("TraceReadRequest"), caller);
                }
                while ((depth < xmlReader.Depth) && xmlReader.Read())
                {
                }
                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    xmlReader.Read();
                }
                this.message.SetParameterValues(objArray);
                objArray2 = objArray;
            }
            catch (SoapException)
            {
                throw;
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                throw new SoapException(System.Web.Services.Res.GetString("WebRequestUnableToRead"), new XmlQualifiedName("Client", "http://schemas.xmlsoap.org/soap/envelope/"), exception2);
            }
            return(objArray2);
        }
示例#6
0
        internal override bool Initialize()
        {
            this.GuessVersion();
            this.message             = new SoapServerMessage(this);
            this.onewayInitException = null;
            this.serverType          = (SoapServerType)base.GetFromCache(typeof(SoapServerProtocol), base.Type);
            if (this.serverType == null)
            {
                lock (ServerProtocol.InternalSyncObject)
                {
                    this.serverType = (SoapServerType)base.GetFromCache(typeof(SoapServerProtocol), base.Type);
                    if (this.serverType == null)
                    {
                        this.serverType = new SoapServerType(base.Type, this.protocolsSupported);
                        base.AddToCache(typeof(SoapServerProtocol), base.Type, this.serverType);
                    }
                }
            }
            Exception innerException = null;

            try
            {
                this.message.highPriConfigExtensions = SoapMessage.InitializeExtensions(this.serverType.HighPriExtensions, this.serverType.HighPriExtensionInitializers);
                this.message.highPriConfigExtensions = this.ModifyInitializedExtensions(PriorityGroup.High, this.message.highPriConfigExtensions);
                this.message.SetStream(base.Request.InputStream);
                this.message.InitExtensionStreamChain(this.message.highPriConfigExtensions);
                this.message.SetStage(SoapMessageStage.BeforeDeserialize);
                this.message.ContentType     = base.Request.ContentType;
                this.message.ContentEncoding = base.Request.Headers["Content-Encoding"];
                this.message.RunExtensions(this.message.highPriConfigExtensions, false);
                innerException = this.message.Exception;
            }
            catch (Exception exception2)
            {
                if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "Initialize", exception2);
                }
                innerException = exception2;
            }
            this.message.allExtensions = this.message.highPriConfigExtensions;
            this.GuessVersion();
            try
            {
                this.serverMethod = this.RouteRequest(this.message);
                if (this.serverMethod == null)
                {
                    throw new SoapException(System.Web.Services.Res.GetString("UnableToHandleRequest0"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"));
                }
            }
            catch (Exception exception3)
            {
                if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                {
                    throw;
                }
                if (this.helper.RequestNamespace != null)
                {
                    this.SetHelper(SoapServerProtocolHelper.GetHelper(this, this.helper.RequestNamespace));
                }
                this.CheckHelperVersion();
                throw;
            }
            this.isOneWay = this.serverMethod.oneWay;
            if (innerException == null)
            {
                try
                {
                    SoapReflectedExtension[] reflectedExtensions = (SoapReflectedExtension[])CombineExtensionsHelper(this.serverMethod.extensions, this.serverType.LowPriExtensions, typeof(SoapReflectedExtension));
                    object[] extensionInitializers = (object[])CombineExtensionsHelper(this.serverMethod.extensionInitializers, this.serverType.LowPriExtensionInitializers, typeof(object));
                    this.message.otherExtensions = SoapMessage.InitializeExtensions(reflectedExtensions, extensionInitializers);
                    this.message.otherExtensions = this.ModifyInitializedExtensions(PriorityGroup.Low, this.message.otherExtensions);
                    this.message.allExtensions   = (SoapExtension[])CombineExtensionsHelper(this.message.highPriConfigExtensions, this.message.otherExtensions, typeof(SoapExtension));
                }
                catch (Exception exception4)
                {
                    if (((exception4 is ThreadAbortException) || (exception4 is StackOverflowException)) || (exception4 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "Initialize", exception4);
                    }
                    innerException = exception4;
                }
            }
            if (innerException != null)
            {
                if (!this.isOneWay)
                {
                    if (innerException is SoapException)
                    {
                        throw innerException;
                    }
                    throw SoapException.Create(this.Version, System.Web.Services.Res.GetString("WebConfigExtensionError"), new XmlQualifiedName("Server", "http://schemas.xmlsoap.org/soap/envelope/"), innerException);
                }
                this.onewayInitException = innerException;
            }
            return(true);
        }
示例#7
0
        internal override object[] ReadParameters()
        {
            message.InitExtensionStreamChain(message.otherExtensions);
            message.RunExtensions(message.otherExtensions);

            // do a sanity check on the content-type before we check the version since otherwise the error might be really nasty
            if (!ContentType.IsSoap(message.ContentType))
            {
                throw new SoapException(Res.GetString(Res.WebRequestContent, message.ContentType, helper.HttpContentType),
                                        new XmlQualifiedName(Soap.ClientCode, Soap.Namespace), new SoapFaultSubcode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }

            // now that all the extensions have run, establish the real version of the request
            SetHelper(SoapServerProtocolHelper.GetHelper(this));
            CheckHelperVersion();

            // now do a more specific content-type check for soap 1.1 only (soap 1.2 allows various xml content types)
            if (version == SoapProtocolVersion.Soap11 && !ContentType.MatchesBase(message.ContentType, helper.HttpContentType))
            {
                throw new SoapException(Res.GetString(Res.WebRequestContent, message.ContentType, helper.HttpContentType),
                                        new XmlQualifiedName(Soap.ClientCode, Soap.Namespace), new SoapFaultSubcode(Soap12FaultCodes.UnsupportedMediaTypeFaultCode));
            }

            try {
                XmlTextReader reader = SoapServerProtocolHelper.GetXmlTextReader(message.ContentType, message.Stream);
                reader.MoveToContent();
                reader.ReadStartElement(Soap.Envelope, helper.EnvelopeNs);
                reader.MoveToContent();

                new SoapHeaderHandling().ReadHeaders(reader, serverMethod.inHeaderSerializer, message.Headers, serverMethod.inHeaderMappings, SoapHeaderDirection.In, helper.EnvelopeNs, serverMethod.use == SoapBindingUse.Encoded ? helper.EncodingNs : null);

                reader.MoveToContent();
                reader.ReadStartElement(Soap.Body, helper.EnvelopeNs);
                reader.MoveToContent();

                // SOAP12: not using encodingStyle
                //object[] values = (object[])serverMethod.parameterSerializer.Deserialize(reader, serverMethod.use == SoapBindingUse.Encoded ? helper.EncodingNs : null);
                object[] values = (object[])serverMethod.parameterSerializer.Deserialize(reader);

                while (reader.NodeType == XmlNodeType.Whitespace)
                {
                    reader.Skip();
                }
                if (reader.NodeType == XmlNodeType.None)
                {
                    reader.Skip();
                }
                else
                {
                    reader.ReadEndElement();
                }
                while (reader.NodeType == XmlNodeType.Whitespace)
                {
                    reader.Skip();
                }
                if (reader.NodeType == XmlNodeType.None)
                {
                    reader.Skip();
                }
                else
                {
                    reader.ReadEndElement();
                }

                message.SetParameterValues(values);

                return(values);
            }
            catch (SoapException) {
                throw;
            }
            catch (Exception e) {
                throw new SoapException(Res.GetString(Res.WebRequestUnableToRead), new XmlQualifiedName(Soap.ClientCode, Soap.Namespace), e);
            }
        }
示例#8
0
        internal override bool Initialize()
        {
            // try to guess the request version so we can handle any exceptions that might come up
            GuessVersion();

            message             = new SoapServerMessage(this);
            onewayInitException = null;

            serverType = (SoapServerType)GetFromCache(typeof(SoapServerProtocol), Type);
            if (serverType == null)
            {
                lock (Type){
                    serverType = (SoapServerType)GetFromCache(typeof(SoapServerProtocol), Type);
                    if (serverType == null)
                    {
                        serverType = new SoapServerType(Type, versionsSupported);
                        AddToCache(typeof(SoapServerProtocol), Type, serverType);
                    }
                }
            }

            // We delay throwing any exceptions out of the extension until we determine if the method is one-way or not.
            Exception extensionException = null;

            try {
                message.highPriConfigExtensions = SoapMessage.InitializeExtensions(serverType.HighPriExtensions, serverType.HighPriExtensionInitializers);
                // For one-way methods we rely on Request.InputStream guaranteeing that the entire request body has arrived
                message.SetStream(Request.InputStream);

                Debug.Assert(message.Stream.CanSeek, "Web services SOAP handler assumes a seekable stream.");

                message.InitExtensionStreamChain(message.highPriConfigExtensions);
                message.SetStage(SoapMessageStage.BeforeDeserialize);
                message.ContentType     = Request.ContentType;
                message.ContentEncoding = Request.Headers[ContentType.ContentEncoding];
                message.RunExtensions(message.highPriConfigExtensions);
            }
            catch (Exception e) {
                extensionException = e;
            }

            // set this here since we might throw before we init the other extensions
            message.allExtensions = message.highPriConfigExtensions;

            // maybe the extensions that just ran changed some of the request data so we can make a better version guess
            GuessVersion();
            try {
                this.serverMethod = helper.RouteRequest();

                // the RouteRequest impl should throw an exception if it can't route the request but just in case...
                if (this.serverMethod == null)
                {
                    throw new SoapException(Res.GetString(Res.UnableToHandleRequest0), new XmlQualifiedName(Soap.ServerCode, Soap.Namespace));
                }
            }
            catch (Exception) {
                if (helper.RequestNamespace != null)
                {
                    SetHelper(SoapServerProtocolHelper.GetHelper(this, helper.RequestNamespace));
                }

                // version mismatches override other errors
                CheckHelperVersion();

                throw;
            }

            this.isOneWay = serverMethod.oneWay;
            if (extensionException == null)
            {
                try {
                    SoapReflectedExtension[] otherReflectedExtensions = (SoapReflectedExtension[])CombineExtensionsHelper(serverMethod.extensions, serverType.LowPriExtensions, typeof(SoapReflectedExtension));
                    object[] otherInitializers = (object[])CombineExtensionsHelper(serverMethod.extensionInitializers, serverType.LowPriExtensionInitializers, typeof(object));
                    message.otherExtensions = SoapMessage.InitializeExtensions(otherReflectedExtensions, otherInitializers);
                    message.allExtensions   = (SoapExtension[])CombineExtensionsHelper(message.highPriConfigExtensions, message.otherExtensions, typeof(SoapExtension));
                }
                catch (Exception e) {
                    extensionException = e;
                }
            }

            if (extensionException != null)
            {
                if (isOneWay)
                {
                    onewayInitException = extensionException;
                }
                else
                {
                    throw new SoapException(Res.GetString(Res.WebConfigExtensionError), new XmlQualifiedName(Soap.ServerCode, Soap.Namespace), extensionException);
                }
            }

            return(true);
        }