コード例 #1
0
        public bool Validate(OiosiMessage oiosiMessage)
        {
            bool result = true;
            SendingOptionConfig sendingOptionConfig = ConfigurationHandler.GetConfigurationSection <SendingOptionConfig>();

            this.logger.Trace("Start SendingValidation");

            if (sendingOptionConfig.SchemaValidationBool)
            {
                this.logger.Trace("Start schema");
                SchemaValidatorWithLookup schemaValidatorWithLookup = new SchemaValidatorWithLookup();
                //string document = oiosiMessage.MessageXml
                XmlDocument document = oiosiMessage.MessageXml;
                schemaValidatorWithLookup.Validate(document.OuterXml);
                result = true;
            }

            if (result && sendingOptionConfig.SchematronValidationBool)
            {
                this.logger.Trace("Start schematron");
                SchematronValidatorWithLookup schematronValidatorWithLookup = new SchematronValidatorWithLookup();
                //string document = oiosiMessage.MessageString;
                XmlDocument document = oiosiMessage.MessageXml;
                schematronValidatorWithLookup.Validate(document.OuterXml);
                result = true;
            }

            this.logger.Trace("Finish SendingValidation");
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Asynchronously starts sending a request
        /// </summary>
        /// <param name="message">Request message</param>
        /// <param name="callback">The asynchronous callback</param>
        /// <returns>Returns an IAsyncResult object</returns>
        public IAsyncResult BeginGetResponse(OiosiMessage message, out Response response, AsyncCallback callback)
        {
            AsyncGetResponse asyncGetResponse = new AsyncGetResponse(GetResponse);
            IAsyncResult     result           = asyncGetResponse.BeginInvoke(message, out response, callback, asyncGetResponse);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg">the message</param>
        public Response(Message msg)
        {
            // Get the xml body
            XmlDocument messageXml = ExtractXmlFromWcfMessage(msg);

            _responseMessage = new OiosiMessage(messageXml);

            // Who was the response from?
            if (msg.Headers.From != null)
            {
                this._responseUri = msg.Headers.From.Uri;
            }
        }
コード例 #4
0
        /// <summary>
        /// Synchronously sends a request and gets a response
        /// </summary>
        /// <example>
        /// Response response;
        /// try{
        ///    GetResponse(request, out response);
        /// }
        /// catch(RequestShutdownException){
        ///    // Sending went well, and we can continue even though we didn't get a neat shutdown
        /// }
        /// catch(Exception e){
        ///     // Sending did not go well
        ///     trow;
        /// }
        /// </example>
        /// <param name="response">The response. If this parameter is set the sending went well and the response is safe to use</param>
        /// <param name="request">Request message</param>
        public void GetResponse(OiosiMessage request, out Response response)
        {
            response = null;
            this.OpenProxy();

            try
            {
                this.SendMessage(request, out response);
            }
            catch
            {
                throw;
            }
            finally
            {
                this.CloseProxy();
            }
        }
コード例 #5
0
        public Response GetResponse(OiosiMessage message)
        {
            System.Diagnostics.Debug.WriteLine(DateTime.Now + " " + this.ToString() + ".GetResponse()");
            Response response = null;

            this.OpenProxy();

            try
            {
                this.SendMessage(message, out response);
            }
            catch
            {
                throw;
            }
            finally
            {
                this.CloseProxy();
            }
            return(response);
        }
コード例 #6
0
        /// <summary>
        /// Converts the message to a wcf message and sends it via the proxy
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private void SendMessage(OiosiMessage message, out Response response)
        {
            response = null;
            try
            {
                // Convert to WCF message
                Message wcfMessage = null;
                if (message.HasBody)
                {
                    XmlReader xmlBody = message.GetMessageXmlReader();
                    wcfMessage = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, message.RequestAction, xmlBody);
                }
                else
                {
                    wcfMessage = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, message.RequestAction);
                }

                // Adds properties from the Message to the WCF message
                foreach (KeyValuePair <string, object> p in message.Properties)
                {
                    wcfMessage.Properties.Add(p.Key, p.Value);
                }

                // Do we have any properties that should be added to WS-RM messages as well?
                if (message.UbiquitousProperties.Count > 0)
                {
                    try
                    {
                        UbiquitousPropertiesBindingElement interceptor = (((CustomBinding)proxy.ChannelFactory.Endpoint.Binding).Elements.Find <UbiquitousPropertiesBindingElement>());
                        interceptor.SetProperties(message.UbiquitousProperties);
                    }
                    catch (NullReferenceException e)
                    {
                        throw new MissingStackElementException("UbiquitousPropertiesBindingElement", e);
                    }
                }

                // Adds custom headers
                foreach (KeyValuePair <XmlQualifiedName, MessageHeader> header in message.MessageHeaders)
                {
                    wcfMessage.Headers.Add(header.Value);
                }

                // Sends
                Message wcfMessageResponse = this.proxy.RequestRespond(wcfMessage);

                // Make sure we dind't receive a fault
                if (wcfMessageResponse.IsFault)
                {
                    throw this.CreateFaultWasReceivedException(new FaultException(MessageFault.CreateFault(wcfMessageResponse, int.MaxValue)));
                }

                // Convert back to oiosi message
                response = new Response(wcfMessageResponse);

                // If any properties with the attribute MessageProperty were sent with the message
                // they should be attached to the ListenerRequest message as well
                foreach (object o in wcfMessageResponse.Properties.Values)
                {
                    object[] attributes = o.GetType().GetCustomAttributes(typeof(dk.gov.oiosi.extension.wcf.OiosiMessagePropertyAttribute), false);
                    if (attributes.Length > 0)
                    {
                        response.AddProperty(o);
                    }
                }
            }
            catch (ProtocolException e)
            {
                // Minor hack to fix interop problems with the Java/Axis2 1.2 NemHandel stack
                // SOAP faults might be returned with a http code 400 (Bad request),
                // if that is the case we need to manually get the SOAP fault from the WebException
                if (e.InnerException is System.Net.WebException)
                {
                    throw this.GetSoapFaultFromHttpException(e.InnerException as System.Net.WebException);
                }
                else
                {
                    throw new ProtocolMismatchException(e);
                }
            }
            catch (MessageSecurityException e)
            {
                // If the execption was not due to a fault
                if (!(e.InnerException is FaultException))
                {
                    throw new ProtocolMismatchException(e);
                }
                else
                {
                    throw this.CreateFaultWasReceivedException((FaultException)e.InnerException);
                }
            }
            catch
            {
                throw;
            }
        }