예제 #1
0
        public virtual void WriteSoapHeader(XmlWriter writer, IXRoadHeader header, HeaderDefinition definition, IEnumerable <XElement> additionalHeaders = null)
        {
            writer.WriteStartElement("Header", NamespaceConstants.SOAP_ENV);

            header?.WriteTo(writer, this, definition);

            foreach (var additionalHeader in additionalHeaders ?? Enumerable.Empty <XElement>())
            {
                additionalHeader.WriteTo(writer);
            }

            writer.WriteEndElement();
        }
예제 #2
0
        /// <summary>
        /// Executes specified X-Road operations with given arguments.
        /// </summary>
        public T Execute <T>(object arg, IXRoadHeader xRoadHeader, IServiceMap serviceMap = null)
        {
            IServiceMap operationServiceMap = null;

            using (var requestMessage = new XRoadMessage(Protocol, xRoadHeader))
            {
                using (var writer = XmlWriter.Create(requestMessage.ContentStream))
                {
                    writer.WriteStartDocument();

                    Protocol.Style.WriteSoapEnvelope(writer, Protocol.ProducerNamespace);
                    if (!string.IsNullOrEmpty(RequestNamespace))
                    {
                        writer.WriteAttributeString(PrefixConstants.XMLNS, "req", NamespaceConstants.XMLNS, RequestNamespace);
                    }

                    Protocol.WriteSoapHeader(writer, xRoadHeader);

                    writer.WriteStartElement("Body", NamespaceConstants.SOAP_ENV);

                    operationServiceMap = serviceMap ?? requestMessage.GetSerializerCache().GetServiceMap(XName.Get(xRoadHeader.Service.ServiceCode, Protocol.ProducerNamespace));
                    operationServiceMap.SerializeRequest(writer, arg, requestMessage, RequestNamespace);

                    writer.WriteEndElement();
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                }

                var request = WebRequest.Create(Uri);

                request.ContentType           = $"text/xml; charset={XRoadEncoding.UTF8.WebName}";
                request.Headers["SOAPAction"] = string.Empty;
                request.Method = "POST";

                BeforeRequest?.Invoke(this, new XRoadRequestEventArgs(request, requestMessage));

                requestMessage.SaveTo(request);

                using (var response = request.GetResponseAsync().Result)
                    using (var responseStream = response.GetResponseStream())
                        using (var seekableStream = new MemoryStream())
                            using (var responseMessage = new XRoadMessage())
                            {
                                responseStream?.CopyTo(seekableStream);
                                BeforeDeserialize?.Invoke(this, new XRoadResponseEventArgs(response, seekableStream));
                                responseMessage.LoadResponse(seekableStream, response.Headers.GetContentTypeHeader(), Path.GetTempPath(), Protocol);
                                return((T)responseMessage.DeserializeMessageContent(operationServiceMap));
                            }
            }
        }
예제 #3
0
        /// <summary>
        /// Serializes header of SOAP message.
        /// </summary>
        public static void WriteSoapHeader(this IXRoadProtocol protocol, XmlWriter writer, IXRoadHeader header, IEnumerable <XElement> additionalHeaders = null)
        {
            writer.WriteStartElement("Header", NamespaceConstants.SOAP_ENV);

            header?.WriteTo(writer, protocol);

            foreach (var additionalHeader in additionalHeaders ?? Enumerable.Empty <XElement>())
            {
                additionalHeader.WriteTo(writer);
            }

            writer.WriteEndElement();
        }
예제 #4
0
 /// <summary>
 /// Initialize new X-Road message of this X-Road message protocol instance.
 /// </summary>
 public static XRoadMessage CreateMessage(this IXRoadProtocol protocol, IXRoadHeader header = null) =>
 new XRoadMessage(protocol, header ?? protocol.HeaderDefinition.CreateInstance());
예제 #5
0
 /// <summary>
 /// Initializes new empty X-Road message for request serialization.
 /// </summary>
 public XRoadMessage(IXRoadProtocol protocol, IXRoadHeader header)
     : this(new MemoryStream())
 {
     Protocol = protocol;
     Header   = header;
 }
예제 #6
0
 /// <summary>
 /// Initializes new empty X-Road message for request serialization.
 /// </summary>
 public XRoadMessage(IServiceManager serviceManager, IXRoadHeader header)
     : this(new MemoryStream())
 {
     ServiceManager = serviceManager;
     Header         = header;
 }