Exemple #1
0
        private SoapClientMessage BeforeSerialize(WebRequest request, string methodName, object[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            SoapClientMethod method = this.clientType.GetMethod(methodName);

            if (method == null)
            {
                throw new ArgumentException(System.Web.Services.Res.GetString("WebInvalidMethodName", new object[1]
                {
                    (object)methodName
                }));
            }
            else
            {
                SoapExtension[]   soapExtensionArray = SoapMessage.InitializeExtensions((SoapReflectedExtension[])SoapHttpClientProtocol.CombineExtensionsHelper((Array)this.clientType.HighPriExtensions, (Array)method.extensions, (Array)this.clientType.LowPriExtensions, typeof(SoapReflectedExtension)), (object[])SoapHttpClientProtocol.CombineExtensionsHelper((Array)this.clientType.HighPriExtensionInitializers, (Array)method.extensionInitializers, (Array)this.clientType.LowPriExtensionInitializers, typeof(object)));
                SoapClientMessage soapClientMessage  = new SoapClientMessage(this, method, this.Url);
                soapClientMessage.initializedExtensions = soapExtensionArray;
                if (soapExtensionArray != null)
                {
                    soapClientMessage.SetExtensionStream(new SoapExtensionStream());
                }
                soapClientMessage.InitExtensionStreamChain(soapClientMessage.initializedExtensions);
                string action = UrlEncoder.EscapeString(method.action, Encoding.UTF8);
                soapClientMessage.SetStage(SoapMessageStage.BeforeSerialize);
                if (this.version == SoapProtocolVersion.Soap12)
                {
                    soapClientMessage.ContentType = ContentType.Compose("application/soap+xml", this.RequestEncoding != null ? this.RequestEncoding : Encoding.UTF8, action);
                }
                else
                {
                    soapClientMessage.ContentType = ContentType.Compose("text/xml", this.RequestEncoding != null ? this.RequestEncoding : Encoding.UTF8);
                }
                soapClientMessage.SetParameterValues(parameters);
                SoapHeaderHandling.GetHeaderMembers(soapClientMessage.Headers, (object)this, method.inHeaderMappings, SoapHeaderDirection.In, true);
                soapClientMessage.RunExtensions(soapClientMessage.initializedExtensions, true);
                request.ContentType = soapClientMessage.ContentType;
                if (soapClientMessage.ContentEncoding != null && soapClientMessage.ContentEncoding.Length > 0)
                {
                    ((NameValueCollection)request.Headers)["Content-Encoding"] = soapClientMessage.ContentEncoding;
                }
                request.Method = "POST";
                if (this.version != SoapProtocolVersion.Soap12 && ((NameValueCollection)request.Headers)["SOAPAction"] == null)
                {
                    StringBuilder stringBuilder = new StringBuilder(action.Length + 2);
                    stringBuilder.Append('"');
                    stringBuilder.Append(action);
                    stringBuilder.Append('"');
                    ((NameValueCollection)request.Headers).Add("SOAPAction", ((object)stringBuilder).ToString());
                }
                return(soapClientMessage);
            }
        }
Exemple #2
0
        private SoapClientMessage BeforeSerialize(WebRequest request, string methodName, object[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            SoapClientMethod method = this.clientType.GetMethod(methodName);

            if (method == null)
            {
                throw new ArgumentException(System.Web.Services.Res.GetString("WebInvalidMethodName", new object[] { methodName }));
            }
            SoapReflectedExtension[] reflectedExtensions = (SoapReflectedExtension[])CombineExtensionsHelper(this.clientType.HighPriExtensions, method.extensions, this.clientType.LowPriExtensions, typeof(SoapReflectedExtension));
            object[]          extensionInitializers      = (object[])CombineExtensionsHelper(this.clientType.HighPriExtensionInitializers, method.extensionInitializers, this.clientType.LowPriExtensionInitializers, typeof(object));
            SoapExtension[]   extensionArray2            = SoapMessage.InitializeExtensions(reflectedExtensions, extensionInitializers);
            SoapClientMessage message = new SoapClientMessage(this, method, base.Url)
            {
                initializedExtensions = extensionArray2
            };

            if (extensionArray2 != null)
            {
                message.SetExtensionStream(new SoapExtensionStream());
            }
            message.InitExtensionStreamChain(message.initializedExtensions);
            string action = UrlEncoder.EscapeString(method.action, Encoding.UTF8);

            message.SetStage(SoapMessageStage.BeforeSerialize);
            if (this.version == SoapProtocolVersion.Soap12)
            {
                message.ContentType = ContentType.Compose("application/soap+xml", (base.RequestEncoding != null) ? base.RequestEncoding : Encoding.UTF8, action);
            }
            else
            {
                message.ContentType = ContentType.Compose("text/xml", (base.RequestEncoding != null) ? base.RequestEncoding : Encoding.UTF8);
            }
            message.SetParameterValues(parameters);
            SoapHeaderHandling.GetHeaderMembers(message.Headers, this, method.inHeaderMappings, SoapHeaderDirection.In, true);
            message.RunExtensions(message.initializedExtensions, true);
            request.ContentType = message.ContentType;
            if ((message.ContentEncoding != null) && (message.ContentEncoding.Length > 0))
            {
                request.Headers["Content-Encoding"] = message.ContentEncoding;
            }
            request.Method = "POST";
            if ((this.version != SoapProtocolVersion.Soap12) && (request.Headers["SOAPAction"] == null))
            {
                StringBuilder builder = new StringBuilder(action.Length + 2);
                builder.Append('"');
                builder.Append(action);
                builder.Append('"');
                request.Headers.Add("SOAPAction", builder.ToString());
            }
            return(message);
        }
Exemple #3
0
        SoapClientMessage BeforeSerialize(WebRequest request, string methodName, object[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            SoapClientMethod method = clientType.GetMethod(methodName);

            if (method == null)
            {
                throw new ArgumentException(Res.GetString(Res.WebInvalidMethodName, methodName));
            }

            // Run BeforeSerialize extension pass. Extensions are not allowed
            // to write into the stream during this pass.
            SoapReflectedExtension[] allExtensions     = (SoapReflectedExtension[])CombineExtensionsHelper(clientType.HighPriExtensions, method.extensions, clientType.LowPriExtensions, typeof(SoapReflectedExtension));
            object[]          allExtensionInitializers = (object[])CombineExtensionsHelper(clientType.HighPriExtensionInitializers, method.extensionInitializers, clientType.LowPriExtensionInitializers, typeof(object));
            SoapExtension[]   initializedExtensions    = SoapMessage.InitializeExtensions(allExtensions, allExtensionInitializers);
            SoapClientMessage message = new SoapClientMessage(this, method, Url);

            message.initializedExtensions = initializedExtensions;
            if (initializedExtensions != null)
            {
                message.SetExtensionStream(new SoapExtensionStream());
            }
            message.InitExtensionStreamChain(message.initializedExtensions);

            string soapAction = UrlEncoder.EscapeString(method.action, Encoding.UTF8);

            message.SetStage(SoapMessageStage.BeforeSerialize);
            if (this.version == SoapProtocolVersion.Soap12)
            {
                message.ContentType = ContentType.Compose(ContentType.ApplicationSoap, RequestEncoding != null ? RequestEncoding : Encoding.UTF8, soapAction);
            }
            else
            {
                message.ContentType = ContentType.Compose(ContentType.TextXml, RequestEncoding != null ? RequestEncoding : Encoding.UTF8);
            }
            message.SetParameterValues(parameters);
            SoapHeaderHandling.GetHeaderMembers(message.Headers, this, method.inHeaderMappings, SoapHeaderDirection.In, true);
            message.RunExtensions(message.initializedExtensions);

            // Last chance to set request headers
            request.ContentType = message.ContentType;
            if (message.ContentEncoding != null && message.ContentEncoding.Length > 0)
            {
                request.Headers[ContentType.ContentEncoding] = message.ContentEncoding;
            }

            request.Method = "POST";
            if (this.version != SoapProtocolVersion.Soap12 && request.Headers[Soap.Action] == null)
            {
                StringBuilder actionStringBuilder = new StringBuilder(soapAction.Length + 2);
                actionStringBuilder.Append('"');
                actionStringBuilder.Append(soapAction);
                actionStringBuilder.Append('"');
                request.Headers.Add(Soap.Action, actionStringBuilder.ToString());
            }

            return(message);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }